Skip to content

Commit 1f1a9e1

Browse files
committed
feat: Use from_hex for strings of length 32
1 parent bd08a09 commit 1f1a9e1

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

ulid/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@ def parse(cls: type[U], value: Any) -> U:
171171
return cls.from_uuid(value)
172172
if isinstance(value, str):
173173
len_value = len(value)
174-
if len_value in {constants.UUID_REPR_LEN, constants.UUID_LEN}:
174+
if len_value == constants.UUID_REPR_LEN:
175175
return cls.from_uuid(uuid.UUID(value))
176+
if len_value == constants.HEX_REPR_LEN:
177+
return cls.from_hex(value)
176178
if len_value == constants.REPR_LEN:
177179
return cls.from_str(value)
178-
if len_value == constants.BYTES_LEN:
179-
return cls.from_hex(value)
180180
raise ValueError(f"Cannot parse ULID from string of length {len_value}")
181181
if isinstance(value, int):
182182
if len(str(value)) == constants.INT_REPR_LEN:

ulid/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from ulid import ULID
1515

1616

17-
if TYPE_CHECKING:
17+
if TYPE_CHECKING: # pragma: no cover
1818
from collections.abc import Callable
1919
from collections.abc import Sequence
2020

ulid/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111

1212
INT_REPR_LEN = 37
1313

14-
UUID_LEN = 32
14+
HEX_REPR_LEN = 32
1515
UUID_REPR_LEN = 36 # UUID with dash-separated segments

0 commit comments

Comments
 (0)