saresend / KSUID

Sortable UIDs in Python
MIT License
95 stars 14 forks source link

Add deserializing from str #8

Open cybercyst opened 3 years ago

cybercyst commented 3 years ago

When serializing something, it is useful to be able to deserialize it back into a useful object... ksuid doesn't seem to allow this currently

I'd expect something like the following to work

def test_ksuid_deserializable():
    from ksuid import ksuid
    id = ksuid()

    serialized_id = str(id)

    id2 = ksuid(serialized_id)

    # not the same object in memory
    assert id is not id2
    # but they serialize to the same value
    assert str(id) == str(id2)