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:
Cacahuete Lenovo Ubuntu 2018-09-16 15:49:12 +02:00
parent 86ef95bd26
commit d1ea1f7317

View file

@ -8,30 +8,17 @@ def unique(seq):
return type(seq)(uniques) return type(seq)(uniques)
class StrType: class StrType(str):
"""Helper class to print and compare object types. """Helper class to print and compare object types.
__eq__ implemented to allow for StrType enumaration Provide the object whose type you want to print.
__hash__ implemented for compatibility with set objects
__repr__ and __str__ to print type(StrType.obj) as desired.
""" """
def __init__(self, obj): def __init__(self, obj):
"""Provide the object whose type you want to print.""" self.value = type(obj).__name__
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))
def __str__(self): def __str__(self):
return f"<{type(self.obj).__name__}>" return f"<{self.value}>"
def __repr__(self): __repr__ = __str__
return self.__str__()
def get_structure(data): def get_structure(data):