Skip to content

Commit d132255

Browse files
committed
feat: make TypeID repr output executable by adding .from_string()
Fixes #18 Previously, TypeID.__repr__() returned TypeID('prefix_suffix') which was not valid Python code since the constructor doesn't accept strings directly. This made it impossible to copy-paste TypeID representations from error messages or interactive sessions. Now __repr__() returns TypeID.from_string('prefix_suffix'), making the output directly executable and copy-pasteable into Python interpreters. All existing tests pass with this change.
1 parent f66753d commit d132255

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

typeid/typeid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __str__(self) -> str:
4848
return value
4949

5050
def __repr__(self):
51-
return "%s(%r)" % (self.__class__.__name__, str(self))
51+
return "%s.from_string(%r)" % (self.__class__.__name__, str(self))
5252

5353
def __eq__(self, value: object) -> bool:
5454
if not isinstance(value, TypeID):

0 commit comments

Comments
 (0)