Code cleaning: StrType class now derives from built-in str so that __hash__ and __eq__ are not to be definded
This commit is contained in:
parent
86ef95bd26
commit
d1ea1f7317
|
|
@ -8,30 +8,17 @@ def unique(seq):
|
|||
return type(seq)(uniques)
|
||||
|
||||
|
||||
class StrType:
|
||||
class StrType(str):
|
||||
"""Helper class to print and compare object types.
|
||||
__eq__ implemented to allow for StrType enumaration
|
||||
__hash__ implemented for compatibility with set objects
|
||||
__repr__ and __str__ to print type(StrType.obj) as desired.
|
||||
Provide the object whose type you want to print.
|
||||
"""
|
||||
|
||||
def __init__(self, obj):
|
||||
"""Provide the object whose type you want to print."""
|
||||
self.obj = obj
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, StrType):
|
||||
return False
|
||||
return type(self.obj) == type(other.obj)
|
||||
|
||||
def __hash__(self):
|
||||
return hash(str(self))
|
||||
self.value = type(obj).__name__
|
||||
|
||||
def __str__(self):
|
||||
return f"<{type(self.obj).__name__}>"
|
||||
return f"<{self.value}>"
|
||||
|
||||
def __repr__(self):
|
||||
return self.__str__()
|
||||
__repr__ = __str__
|
||||
|
||||
|
||||
def get_structure(data):
|
||||
|
|
|
|||
Loading…
Reference in a new issue