mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-13 19:18:56 +00:00
style(core): define obj_eq and obj_repr so that they pass type-check
This commit is contained in:
parent
456959545c
commit
80f6463799
@ -38,7 +38,7 @@ class UiConfirm:
|
||||
def confirm_dialog(self, ctx: wire.Context) -> Awaitable[Any]:
|
||||
raise NotImplementedError
|
||||
|
||||
__eq__ = utils.obj_eq # type: ignore
|
||||
__eq__ = utils.obj_eq
|
||||
|
||||
|
||||
class UiConfirmOutput(UiConfirm):
|
||||
|
@ -298,31 +298,31 @@ class BufferReader:
|
||||
return byte
|
||||
|
||||
|
||||
def obj_eq(l: object, r: object) -> bool:
|
||||
def obj_eq(self: object, __o: object) -> bool:
|
||||
"""
|
||||
Compares object contents, supports __slots__.
|
||||
"""
|
||||
if l.__class__ is not r.__class__:
|
||||
if self.__class__ is not __o.__class__:
|
||||
return False
|
||||
if not hasattr(l, "__slots__"):
|
||||
return l.__dict__ == r.__dict__
|
||||
if l.__slots__ is not r.__slots__:
|
||||
if not hasattr(self, "__slots__"):
|
||||
return self.__dict__ == __o.__dict__
|
||||
if self.__slots__ is not __o.__slots__:
|
||||
return False
|
||||
for slot in l.__slots__:
|
||||
if getattr(l, slot, None) != getattr(r, slot, None):
|
||||
for slot in self.__slots__:
|
||||
if getattr(self, slot, None) != getattr(__o, slot, None):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def obj_repr(o: object) -> str:
|
||||
def obj_repr(self: object) -> str:
|
||||
"""
|
||||
Returns a string representation of object, supports __slots__.
|
||||
"""
|
||||
if hasattr(o, "__slots__"):
|
||||
d = {attr: getattr(o, attr, None) for attr in o.__slots__}
|
||||
if hasattr(self, "__slots__"):
|
||||
d = {attr: getattr(self, attr, None) for attr in self.__slots__}
|
||||
else:
|
||||
d = o.__dict__
|
||||
return f"<{o.__class__.__name__}: {d}>"
|
||||
d = self.__dict__
|
||||
return f"<{self.__class__.__name__}: {d}>"
|
||||
|
||||
|
||||
def truncate_utf8(string: str, max_bytes: int) -> str:
|
||||
|
Loading…
Reference in New Issue
Block a user