11from abc import ABC , abstractmethod
2- from enum import Enum
32from typing import List , Union
43
54
6- class IdType (str , Enum ):
7- DataRowId = "UID"
8- GlobalKey = "GLOBAL_KEY"
9-
10-
115class Identifiable (ABC ):
126
13- def __init__ (self , keys : Union [str , List [str ]], id_type : IdType ):
14- self ._keys = keys
15- if isinstance (keys , str ):
16- self ._keys = [keys ]
17- self ._id_type = id_type
7+ def __init__ (self , key : str ):
8+ self ._key = key
189
1910 @property
20- def keys (self ):
21- return self ._keys
22-
23- @keys .setter
24- def keys (self , keys ):
25- self ._keys = keys
26- if isinstance (keys , str ):
27- self ._keys = [keys ]
28-
29- @classmethod
30- @abstractmethod
31- def strings_to_identifiable (cls , keys : Union [str , List [str ]]):
32- pass
11+ def key (self ):
12+ return self .key
3313
3414 def __eq__ (self , other ):
35- return other .keys == self .keys
15+ return other .key == self .key
3616
3717 def __hash__ (self ):
38- hash (self .keys )
18+ hash (self .key )
3919
4020 def __str__ (self ):
41- return self .keys .__str__ ()
42-
43-
44- class UniqueIds (Identifiable ):
45-
46- @classmethod
47- def strings_to_identifiable (cls , keys : Union [str , List [str ]]):
48- return cls (keys )
49-
50- def __init__ (self , keys : Union [str , List [str ]]):
51- super ().__init__ (keys , IdType .DataRowId )
52-
53-
54- class GlobalKeys (Identifiable ):
21+ return self .key .__str__ ()
5522
56- @classmethod
57- def strings_to_identifiable (cls , keys : Union [str , List [str ]]):
58- return cls (keys )
5923
60- def __init__ ( self , keys : Union [ str , List [ str ]] ):
61- super (). __init__ ( keys , IdType . GlobalKey )
24+ class UniqueId ( Identifiable ):
25+ pass
6226
6327
64- DefaultIdentifiable = UniqueIds
65- DataRowIdentifiers = Union [ UniqueIds , GlobalKeys ]
28+ class GlobalKey ( Identifiable ):
29+ pass
0 commit comments