11import uuid
22import warnings
3- from typing import Optional
3+ from typing import Generic , Optional , TypeVar
44
55import uuid6
66
77from typeid import base32
88from typeid .errors import InvalidTypeIDStringException
99from typeid .validation import validate_prefix , validate_suffix
1010
11+ PrefixT = TypeVar ("PrefixT" , bound = str )
1112
12- class TypeID :
13- def __init__ (self , prefix : Optional [str ] = None , suffix : Optional [str ] = None ) -> None :
13+
14+ class TypeID (Generic [PrefixT ]):
15+ def __init__ (self , prefix : Optional [PrefixT ] = None , suffix : Optional [str ] = None ) -> None :
1416 suffix = _convert_uuid_to_b32 (uuid6 .uuid7 ()) if not suffix else suffix
1517 validate_suffix (suffix = suffix )
16- if prefix :
18+
19+ if prefix is not None :
1720 validate_prefix (prefix = prefix )
1821
19- self ._prefix = prefix or ""
20- self ._suffix = suffix
22+ self ._prefix : Optional [ PrefixT ] = prefix
23+ self ._suffix : str = suffix
2124
2225 @classmethod
23- def from_string (cls , string : str ):
26+ def from_string (cls , string : str ) -> "TypeID" :
2427 prefix , suffix = get_prefix_and_suffix (string = string )
2528 return cls (suffix = suffix , prefix = prefix )
2629
2730 @classmethod
28- def from_uuid (cls , suffix : uuid .UUID , prefix : Optional [str ] = None ):
31+ def from_uuid (cls , suffix : uuid .UUID , prefix : Optional [PrefixT ] = None ) -> "TypeID" :
2932 suffix_str = _convert_uuid_to_b32 (suffix )
3033 return cls (suffix = suffix_str , prefix = prefix )
3134
@@ -35,7 +38,7 @@ def suffix(self) -> str:
3538
3639 @property
3740 def prefix (self ) -> str :
38- return self ._prefix
41+ return self ._prefix or ""
3942
4043 @property
4144 def uuid (self ) -> uuid6 .UUID :
0 commit comments