Refactor RpcError and BadMessageError to use direct attribute for 'caused_by'

This commit is contained in:
Jahongir Qurbonov 2025-09-16 11:29:00 +05:00
parent 38eae1e21a
commit 8d256aeef9
No known key found for this signature in database
GPG Key ID: 256976CED13D5F2D

View File

@ -69,7 +69,7 @@ class RpcError(ValueError):
self._code = code
self._name = name
self._value = value
self._caused_by = caused_by
self.caused_by: int | None = caused_by
@property
def code(self) -> int:
@ -96,20 +96,6 @@ class RpcError(ValueError):
"""
return self._value
@property
def caused_by(self) -> Optional[int]:
"""
Constructor identifier of the request that caused the error, if known.
"""
return self._caused_by
@caused_by.setter
def caused_by(self, value: int) -> None:
"""
Constructor identifier of the request that caused the error, if known.
"""
self._caused_by = value
@classmethod
def _from_mtproto_error(cls, error: GeneratedRpcError) -> Self:
if m := re.search(r"-?\d+", error.error_message):
@ -172,7 +158,7 @@ class BadMessageError(ValueError):
self.msg_id = msg_id
self._code = code
self._caused_by = caused_by
self.caused_by: int | None = caused_by
self.severity = (
logging.WARNING if self._code in NON_FATAL_MSG_IDS else logging.ERROR
)
@ -189,14 +175,6 @@ class BadMessageError(ValueError):
def fatal(self) -> bool:
return self._code not in NON_FATAL_MSG_IDS
@property
def caused_by(self) -> Optional[int]:
return self._caused_by
@caused_by.setter
def caused_by(self, value: int) -> None:
self._caused_by = value
def __eq__(self, other: object) -> bool:
if not isinstance(other, self.__class__):
return NotImplemented