mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 14:58:09 +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]:
|
def confirm_dialog(self, ctx: wire.Context) -> Awaitable[Any]:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
__eq__ = utils.obj_eq # type: ignore
|
__eq__ = utils.obj_eq
|
||||||
|
|
||||||
|
|
||||||
class UiConfirmOutput(UiConfirm):
|
class UiConfirmOutput(UiConfirm):
|
||||||
|
@ -298,31 +298,31 @@ class BufferReader:
|
|||||||
return byte
|
return byte
|
||||||
|
|
||||||
|
|
||||||
def obj_eq(l: object, r: object) -> bool:
|
def obj_eq(self: object, __o: object) -> bool:
|
||||||
"""
|
"""
|
||||||
Compares object contents, supports __slots__.
|
Compares object contents, supports __slots__.
|
||||||
"""
|
"""
|
||||||
if l.__class__ is not r.__class__:
|
if self.__class__ is not __o.__class__:
|
||||||
return False
|
return False
|
||||||
if not hasattr(l, "__slots__"):
|
if not hasattr(self, "__slots__"):
|
||||||
return l.__dict__ == r.__dict__
|
return self.__dict__ == __o.__dict__
|
||||||
if l.__slots__ is not r.__slots__:
|
if self.__slots__ is not __o.__slots__:
|
||||||
return False
|
return False
|
||||||
for slot in l.__slots__:
|
for slot in self.__slots__:
|
||||||
if getattr(l, slot, None) != getattr(r, slot, None):
|
if getattr(self, slot, None) != getattr(__o, slot, None):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def obj_repr(o: object) -> str:
|
def obj_repr(self: object) -> str:
|
||||||
"""
|
"""
|
||||||
Returns a string representation of object, supports __slots__.
|
Returns a string representation of object, supports __slots__.
|
||||||
"""
|
"""
|
||||||
if hasattr(o, "__slots__"):
|
if hasattr(self, "__slots__"):
|
||||||
d = {attr: getattr(o, attr, None) for attr in o.__slots__}
|
d = {attr: getattr(self, attr, None) for attr in self.__slots__}
|
||||||
else:
|
else:
|
||||||
d = o.__dict__
|
d = self.__dict__
|
||||||
return f"<{o.__class__.__name__}: {d}>"
|
return f"<{self.__class__.__name__}: {d}>"
|
||||||
|
|
||||||
|
|
||||||
def truncate_utf8(string: str, max_bytes: int) -> str:
|
def truncate_utf8(string: str, max_bytes: int) -> str:
|
||||||
|
Loading…
Reference in New Issue
Block a user