fix(core): drop support for __slots__ from obj_eq / obj_repr

__slots__ are unsupported in micropython

[no changelog]
pull/2227/head
matejcik 2 years ago committed by matejcik
parent 33c174491f
commit 221a7c9973

@ -304,29 +304,20 @@ class BufferReader:
def obj_eq(self: Any, __o: Any) -> bool:
"""
Compares object contents, supports __slots__.
Compares object contents.
"""
if self.__class__ is not __o.__class__:
return False
if not hasattr(self, "__slots__"):
return self.__dict__ == __o.__dict__
if self.__slots__ is not __o.__slots__:
return False
for slot in self.__slots__:
if getattr(self, slot, None) != getattr(__o, slot, None):
return False
return True
assert not hasattr(self, "__slots__")
return self.__dict__ == __o.__dict__
def obj_repr(self: Any) -> str:
"""
Returns a string representation of object, supports __slots__.
Returns a string representation of object.
"""
if hasattr(self, "__slots__"):
d = {attr: getattr(self, attr, None) for attr in self.__slots__}
else:
d = self.__dict__
return f"<{self.__class__.__name__}: {d}>"
assert not hasattr(self, "__slots__")
return f"<{self.__class__.__name__}: {self.__dict__}>"
def truncate_utf8(string: str, max_bytes: int) -> str:

Loading…
Cancel
Save