1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-20 21:38:26 +00:00

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

__slots__ are unsupported in micropython

[no changelog]
This commit is contained in:
matejcik 2022-04-13 10:37:07 +02:00 committed by matejcik
parent 33c174491f
commit 221a7c9973

View File

@ -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: