From 80f6463799a52166ee289d9b578aa9fc0d57f639 Mon Sep 17 00:00:00 2001 From: matejcik Date: Fri, 7 Jan 2022 13:39:29 +0100 Subject: [PATCH] style(core): define obj_eq and obj_repr so that they pass type-check --- core/src/apps/bitcoin/sign_tx/helpers.py | 2 +- core/src/trezor/utils.py | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/core/src/apps/bitcoin/sign_tx/helpers.py b/core/src/apps/bitcoin/sign_tx/helpers.py index 72e005c15..cdc16c7b6 100644 --- a/core/src/apps/bitcoin/sign_tx/helpers.py +++ b/core/src/apps/bitcoin/sign_tx/helpers.py @@ -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): diff --git a/core/src/trezor/utils.py b/core/src/trezor/utils.py index 7b1de77fc..0e9b08ecf 100644 --- a/core/src/trezor/utils.py +++ b/core/src/trezor/utils.py @@ -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: