From 126a9fd77eabf9e2caf151069149d92d3a6db6d5 Mon Sep 17 00:00:00 2001 From: Aditya Yadav Date: Fri, 13 Oct 2023 14:17:49 +0530 Subject: [PATCH 01/10] add dunder method docstring --- docs/source/telegram.bot.rst | 1 - docs/source/telegram.ext.application.rst | 1 - docs/source/telegram.ext.basehandler.rst | 1 - docs/source/telegram.ext.conversationhandler.rst | 1 - docs/source/telegram.ext.extbot.rst | 1 - docs/source/telegram.ext.job.rst | 1 - docs/source/telegram.ext.jobqueue.rst | 1 - docs/source/telegram.telegramobject.rst | 1 - telegram/_bot.py | 7 +++++++ telegram/error.py | 15 +++++++++++++++ 10 files changed, 22 insertions(+), 8 deletions(-) diff --git a/docs/source/telegram.bot.rst b/docs/source/telegram.bot.rst index 46f4061cfe8..93211517ee4 100644 --- a/docs/source/telegram.bot.rst +++ b/docs/source/telegram.bot.rst @@ -4,4 +4,3 @@ Bot .. autoclass:: telegram.Bot :members: :show-inheritance: - :special-members: __repr__, __reduce__, __deepcopy__ \ No newline at end of file diff --git a/docs/source/telegram.ext.application.rst b/docs/source/telegram.ext.application.rst index eadc2892776..4b1a3f25991 100644 --- a/docs/source/telegram.ext.application.rst +++ b/docs/source/telegram.ext.application.rst @@ -4,4 +4,3 @@ Application .. autoclass:: telegram.ext.Application :members: :show-inheritance: - :special-members: __repr__ diff --git a/docs/source/telegram.ext.basehandler.rst b/docs/source/telegram.ext.basehandler.rst index 579302c2977..9dfd607cee8 100644 --- a/docs/source/telegram.ext.basehandler.rst +++ b/docs/source/telegram.ext.basehandler.rst @@ -4,4 +4,3 @@ BaseHandler .. autoclass:: telegram.ext.BaseHandler :members: :show-inheritance: - :special-members: __repr__ diff --git a/docs/source/telegram.ext.conversationhandler.rst b/docs/source/telegram.ext.conversationhandler.rst index bc42914f5b7..3ec96f1fdd6 100644 --- a/docs/source/telegram.ext.conversationhandler.rst +++ b/docs/source/telegram.ext.conversationhandler.rst @@ -4,4 +4,3 @@ ConversationHandler .. autoclass:: telegram.ext.ConversationHandler :members: :show-inheritance: - :special-members: __repr__ diff --git a/docs/source/telegram.ext.extbot.rst b/docs/source/telegram.ext.extbot.rst index dee1be3e7cc..d61a36b0789 100644 --- a/docs/source/telegram.ext.extbot.rst +++ b/docs/source/telegram.ext.extbot.rst @@ -4,4 +4,3 @@ ExtBot .. autoclass:: telegram.ext.ExtBot :show-inheritance: :members: insert_callback_data, defaults, rate_limiter, initialize, shutdown, callback_data_cache - :special-members: __repr__ diff --git a/docs/source/telegram.ext.job.rst b/docs/source/telegram.ext.job.rst index 8406fcb80de..0f69756b371 100644 --- a/docs/source/telegram.ext.job.rst +++ b/docs/source/telegram.ext.job.rst @@ -4,4 +4,3 @@ Job .. autoclass:: telegram.ext.Job :members: :show-inheritance: - :special-members: __call__, __repr__ diff --git a/docs/source/telegram.ext.jobqueue.rst b/docs/source/telegram.ext.jobqueue.rst index da347b3bec4..75658e30d3f 100644 --- a/docs/source/telegram.ext.jobqueue.rst +++ b/docs/source/telegram.ext.jobqueue.rst @@ -4,4 +4,3 @@ JobQueue .. autoclass:: telegram.ext.JobQueue :members: :show-inheritance: - :special-members: __repr__ diff --git a/docs/source/telegram.telegramobject.rst b/docs/source/telegram.telegramobject.rst index 65fb7a9cc5d..7f1e5dbb7fa 100644 --- a/docs/source/telegram.telegramobject.rst +++ b/docs/source/telegram.telegramobject.rst @@ -4,4 +4,3 @@ TelegramObject .. autoclass:: telegram.TelegramObject :members: :show-inheritance: - :special-members: __repr__, __getitem__, __eq__, __hash__, __setstate__, __getstate__, __deepcopy__, __setattr__, __delattr__ diff --git a/telegram/_bot.py b/telegram/_bot.py index a798a2b39e7..ebe92e97387 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -363,6 +363,13 @@ def __deepcopy__(self, memodict: Dict[int, object]) -> NoReturn: raise TypeError("Bot objects cannot be deepcopied!") def __eq__(self, other: object) -> bool: + """Defines equality condition for the :class:`telegram.Bot` object. + Two objects of this class are considered to be equal if their all parameters + are identical. + + Returns: + :obj:`True` if both objects have all parameters identical. :obj:`False` otherwise. + """ if isinstance(other, self.__class__): return self.bot == other.bot return False diff --git a/telegram/error.py b/telegram/error.py index 56273328315..65867c2494e 100644 --- a/telegram/error.py +++ b/telegram/error.py @@ -78,12 +78,27 @@ def __init__(self, message: str): self.message: str = msg def __str__(self) -> str: + """Get the string representation of exception message. + + Returns: + :obj:`str` + """ return self.message def __repr__(self) -> str: + """Get the string representation of exception with name and message. + + Returns: + :obj:`str` + """ return f"{self.__class__.__name__}('{self.message}')" def __reduce__(self) -> Tuple[type, Tuple[str]]: + """ + + Returns: + :obj:`tuple` + """ return self.__class__, (self.message,) From 00f55bc3e325a9f5485440021dcd0ef874a9bae1 Mon Sep 17 00:00:00 2001 From: Aditya Yadav Date: Sun, 29 Oct 2023 21:46:11 +0530 Subject: [PATCH 02/10] some docstrings --- telegram/_bot.py | 7 +++++++ telegram/error.py | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/telegram/_bot.py b/telegram/_bot.py index ebe92e97387..560fe2c5731 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -375,6 +375,13 @@ def __eq__(self, other: object) -> bool: return False def __hash__(self) -> int: + """Gives the hash value for the :class:`telegram.Bot` object. + Two objects that compare equal must also have the same hash value, but the + reverse is not necessarily true. + + Returns: + :obj:`int` The hash value of the object. + """ return hash((self.__class__, self.bot)) def __repr__(self) -> str: diff --git a/telegram/error.py b/telegram/error.py index 65867c2494e..86456d22e80 100644 --- a/telegram/error.py +++ b/telegram/error.py @@ -94,7 +94,8 @@ def __repr__(self) -> str: return f"{self.__class__.__name__}('{self.message}')" def __reduce__(self) -> Tuple[type, Tuple[str]]: - """ + """Defines how to serialize the exception for pickle. See + :py:meth:`object.__reduce__` for more info. Returns: :obj:`tuple` From bf322ad1c7b01e88601291801a3b8f8537b4acfd Mon Sep 17 00:00:00 2001 From: Aditya Yadav Date: Mon, 30 Oct 2023 17:50:54 +0530 Subject: [PATCH 03/10] docstring-dunder-methods --- telegram/_bot.py | 5 ++--- telegram/error.py | 2 +- telegram/ext/_callbackdatacache.py | 6 ++++++ telegram/ext/_defaults.py | 13 +++++++++++++ telegram/ext/_jobqueue.py | 23 +++++++++++++++++++++++ telegram/ext/filters.py | 21 +++++++++++++++++++++ 6 files changed, 66 insertions(+), 4 deletions(-) diff --git a/telegram/_bot.py b/telegram/_bot.py index 560fe2c5731..f45920124df 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -375,9 +375,8 @@ def __eq__(self, other: object) -> bool: return False def __hash__(self) -> int: - """Gives the hash value for the :class:`telegram.Bot` object. - Two objects that compare equal must also have the same hash value, but the - reverse is not necessarily true. + """Builds a hash value for this object such that the hash of two objects is + equal if and only if the objects are equal in terms of :meth:`__eq__`. Returns: :obj:`int` The hash value of the object. diff --git a/telegram/error.py b/telegram/error.py index 86456d22e80..600669ee290 100644 --- a/telegram/error.py +++ b/telegram/error.py @@ -86,7 +86,7 @@ def __str__(self) -> str: return self.message def __repr__(self) -> str: - """Get the string representation of exception with name and message. + """Get the unambiguous string representation of exception. Returns: :obj:`str` diff --git a/telegram/ext/_callbackdatacache.py b/telegram/ext/_callbackdatacache.py index 38e86b0faff..fb718d758b6 100644 --- a/telegram/ext/_callbackdatacache.py +++ b/telegram/ext/_callbackdatacache.py @@ -69,6 +69,12 @@ def __init__(self, callback_data: Optional[str] = None) -> None: self.callback_data: Optional[str] = callback_data def __reduce__(self) -> Tuple[type, Tuple[Optional[str]]]: # type: ignore[override] + """Defines how to serialize the exception for pickle. See + :py:meth:`object.__reduce__` for more info. + + Returns: + :obj:`tuple` + """ return self.__class__, (self.callback_data,) diff --git a/telegram/ext/_defaults.py b/telegram/ext/_defaults.py index 3b596e67515..33eaae09339 100644 --- a/telegram/ext/_defaults.py +++ b/telegram/ext/_defaults.py @@ -105,6 +105,12 @@ def __init__( self._api_defaults[kwarg] = value def __hash__(self) -> int: + """Builds a hash value for this object such that the hash of two objects is equal if and + only if the objects are equal in terms of :meth:`__eq__`. + + Returns: + :obj:`int` The hash value of the object. + """ return hash( ( self._parse_mode, @@ -119,6 +125,13 @@ def __hash__(self) -> int: ) def __eq__(self, other: object) -> bool: + """Defines equality condition for the :class:`Defaults` object. + Two objects of this class are considered to be equal if their all parameters + are identical. + + Returns: + :obj:`True` if both objects have all parameters identical. :obj:`False` otherwise. + """ if isinstance(other, Defaults): return all(getattr(self, attr) == getattr(other, attr) for attr in self.__slots__) return False diff --git a/telegram/ext/_jobqueue.py b/telegram/ext/_jobqueue.py index 339d9466102..e2a5556cef4 100644 --- a/telegram/ext/_jobqueue.py +++ b/telegram/ext/_jobqueue.py @@ -779,6 +779,15 @@ def __init__( self._job = cast("APSJob", None) # skipcq: PTC-W0052 def __getattr__(self, item: str) -> object: + """Get the specific attribute of :class:`telegram.ext.Job` object. + + Returns: + :object: The value of the attribute. + + Raises: + :exc:`AttributeError`: If the attribute does not exist in both + :class:`telegram.ext.Job` and :class:`apscheduler.job.Job` objects. + """ try: return getattr(self.job, item) except AttributeError as exc: @@ -787,11 +796,25 @@ def __getattr__(self, item: str) -> object: ) from exc def __eq__(self, other: object) -> bool: + """Defines equality condition for the :class:`telegram.ext.Job` object. + Two objects of this class are considered to be equal if their :paramref:`id` + are equal. + + Returns: + :obj:`True` if both objects have :paramref:`id` parameters identical. + :obj:`False` otherwise. + """ if isinstance(other, self.__class__): return self.id == other.id return False def __hash__(self) -> int: + """Builds a hash value for this object such that the hash of two objects is + equal if and only if the objects are equal in terms of :meth:`__eq__`. + + Returns: + :obj:`int`: The hash value of the object. + """ return hash(self.id) def __repr__(self) -> str: diff --git a/telegram/ext/filters.py b/telegram/ext/filters.py index a8fef2e0a2a..6233254ec76 100644 --- a/telegram/ext/filters.py +++ b/telegram/ext/filters.py @@ -183,18 +183,39 @@ def __init__(self, name: Optional[str] = None, data_filter: bool = False): self._data_filter = data_filter def __and__(self, other: "BaseFilter") -> "BaseFilter": + """Defines `AND` bitwise operator for :class:`BaseFilter` object. + + Returns: + :obj:`BaseFilter` + """ return _MergedFilter(self, and_filter=other) def __or__(self, other: "BaseFilter") -> "BaseFilter": + """Defines `OR` bitwise operator for :class:`BaseFilter` object. + + Returns: + :obj:`BaseFilter` + """ return _MergedFilter(self, or_filter=other) def __xor__(self, other: "BaseFilter") -> "BaseFilter": + """Defines `XOR` bitwise operator for :class:`BaseFilter` object. + + Returns: + :obj:`BaseFilter` + """ return _XORFilter(self, other) def __invert__(self) -> "BaseFilter": + """Defines `NOT` bitwise operator for :class:`BaseFilter` object. + + Returns: + :obj:`BaseFilter` + """ return _InvertedFilter(self) def __repr__(self) -> str: + """:obj:`str`: Name for this filter.""" return self.name @property From 1a113f3b88f1856194d37cbc1f6dd53151fa7472 Mon Sep 17 00:00:00 2001 From: Aditya Yadav Date: Fri, 3 Nov 2023 22:02:46 +0530 Subject: [PATCH 04/10] review 1 --- telegram/_bot.py | 13 ++++--------- telegram/error.py | 10 ++++++---- telegram/ext/_jobqueue.py | 6 +++++- telegram/ext/filters.py | 20 +++++++++++++++++++- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/telegram/_bot.py b/telegram/_bot.py index f45920124df..37272aa87f5 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -364,23 +364,18 @@ def __deepcopy__(self, memodict: Dict[int, object]) -> NoReturn: def __eq__(self, other: object) -> bool: """Defines equality condition for the :class:`telegram.Bot` object. - Two objects of this class are considered to be equal if their all parameters - are identical. + Two objects of this class are considered to be equal if their attributes + :attr:`bot` are equal. Returns: - :obj:`True` if both objects have all parameters identical. :obj:`False` otherwise. + :obj:`True` if both attributes :attr:`bot` are equal. :obj:`False` otherwise. """ if isinstance(other, self.__class__): return self.bot == other.bot return False def __hash__(self) -> int: - """Builds a hash value for this object such that the hash of two objects is - equal if and only if the objects are equal in terms of :meth:`__eq__`. - - Returns: - :obj:`int` The hash value of the object. - """ + """See :meth:`telegram.TelegramObject.__hash__`""" return hash((self.__class__, self.bot)) def __repr__(self) -> str: diff --git a/telegram/error.py b/telegram/error.py index 600669ee290..25502f52e63 100644 --- a/telegram/error.py +++ b/telegram/error.py @@ -78,7 +78,7 @@ def __init__(self, message: str): self.message: str = msg def __str__(self) -> str: - """Get the string representation of exception message. + """Gives the string representation of exceptions message. Returns: :obj:`str` @@ -86,7 +86,7 @@ def __str__(self) -> str: return self.message def __repr__(self) -> str: - """Get the unambiguous string representation of exception. + """Gives an unambiguous string representation of the exception. Returns: :obj:`str` @@ -94,8 +94,10 @@ def __repr__(self) -> str: return f"{self.__class__.__name__}('{self.message}')" def __reduce__(self) -> Tuple[type, Tuple[str]]: - """Defines how to serialize the exception for pickle. See - :py:meth:`object.__reduce__` for more info. + """Defines how to serialize the exception for pickle. + + .. seealso:: + :py:meth:`object.__reduce__`, :mod:`pickle`. Returns: :obj:`tuple` diff --git a/telegram/ext/_jobqueue.py b/telegram/ext/_jobqueue.py index e2a5556cef4..a0ca6ee10ec 100644 --- a/telegram/ext/_jobqueue.py +++ b/telegram/ext/_jobqueue.py @@ -779,7 +779,11 @@ def __init__( self._job = cast("APSJob", None) # skipcq: PTC-W0052 def __getattr__(self, item: str) -> object: - """Get the specific attribute of :class:`telegram.ext.Job` object. + """Overrides :py:meth:`object.__getattr__` to get specific attribute of + object :class:`telegram.ext.Job` object if exists. + + Args: + token (:obj:`str`): The name of the attribute. Returns: :object: The value of the attribute. diff --git a/telegram/ext/filters.py b/telegram/ext/filters.py index 6233254ec76..1c40ef450a1 100644 --- a/telegram/ext/filters.py +++ b/telegram/ext/filters.py @@ -184,6 +184,9 @@ def __init__(self, name: Optional[str] = None, data_filter: bool = False): def __and__(self, other: "BaseFilter") -> "BaseFilter": """Defines `AND` bitwise operator for :class:`BaseFilter` object. + The combined filter accepts an update only if it is accepted by both filters. + For exampe, filters.PHOTO & filters.CAPTION will only accept messages that contain + both a photo and a caption Returns: :obj:`BaseFilter` @@ -192,6 +195,9 @@ def __and__(self, other: "BaseFilter") -> "BaseFilter": def __or__(self, other: "BaseFilter") -> "BaseFilter": """Defines `OR` bitwise operator for :class:`BaseFilter` object. + The combined filter accepts an update only if it is accepted by any of the filters. + For example, filters.PHOTO | filters.CAPTION will only accept messages that contain + photo or caption or both. Returns: :obj:`BaseFilter` @@ -200,6 +206,9 @@ def __or__(self, other: "BaseFilter") -> "BaseFilter": def __xor__(self, other: "BaseFilter") -> "BaseFilter": """Defines `XOR` bitwise operator for :class:`BaseFilter` object. + The combined filter accepts an update only if it is accepted by any of the filters and + not both of them. For example, filters.PHOTO ^ filters.CAPTION will only accept messages + that contain photo or caption, not both of them. Returns: :obj:`BaseFilter` @@ -208,6 +217,8 @@ def __xor__(self, other: "BaseFilter") -> "BaseFilter": def __invert__(self) -> "BaseFilter": """Defines `NOT` bitwise operator for :class:`BaseFilter` object. + The combined filter accepts an update only if it is accepted by any of the filters. + For example, ~ filters.PHOTO will only accept messages that do not contain photo. Returns: :obj:`BaseFilter` @@ -215,7 +226,14 @@ def __invert__(self) -> "BaseFilter": return _InvertedFilter(self) def __repr__(self) -> str: - """:obj:`str`: Name for this filter.""" + """Gives name for this filter. + + .. seealso:: + :meth:`name` + + Returns: + :obj:`str`: + """ return self.name @property From 7e7d5fd060ce9fb15c1204e874becc43aa8db9d2 Mon Sep 17 00:00:00 2001 From: Aditya Yadav Date: Fri, 3 Nov 2023 22:18:12 +0530 Subject: [PATCH 05/10] fix typo --- telegram/ext/_jobqueue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram/ext/_jobqueue.py b/telegram/ext/_jobqueue.py index a0ca6ee10ec..90098c04264 100644 --- a/telegram/ext/_jobqueue.py +++ b/telegram/ext/_jobqueue.py @@ -783,7 +783,7 @@ def __getattr__(self, item: str) -> object: object :class:`telegram.ext.Job` object if exists. Args: - token (:obj:`str`): The name of the attribute. + item (:obj:`str`): The name of the attribute. Returns: :object: The value of the attribute. From ea848e849ba5865d6e7cf3fbe7af103ef0644d5c Mon Sep 17 00:00:00 2001 From: Aditya Date: Thu, 9 Nov 2023 14:05:58 +0530 Subject: [PATCH 06/10] review 2 --- docs/source/telegram.ext.filters.rst | 2 +- docs/source/telegram.ext.updater.rst | 1 - telegram/ext/_defaults.py | 2 +- telegram/ext/_jobqueue.py | 11 ++++++----- telegram/ext/filters.py | 12 ++++++------ 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/source/telegram.ext.filters.rst b/docs/source/telegram.ext.filters.rst index 24306dca3ae..7762ab01036 100644 --- a/docs/source/telegram.ext.filters.rst +++ b/docs/source/telegram.ext.filters.rst @@ -5,7 +5,7 @@ filters Module The classes in `filters.py` are sorted alphabetically such that :bysource: still is readable .. automodule:: telegram.ext.filters - :inherited-members: BaseFilter, MessageFilter, UpdateFilter + :inherited-members: BaseFilter, MessageFilter, UpdateFilter, object :members: :show-inheritance: :member-order: bysource \ No newline at end of file diff --git a/docs/source/telegram.ext.updater.rst b/docs/source/telegram.ext.updater.rst index 98daf6e7c5e..642ddd20209 100644 --- a/docs/source/telegram.ext.updater.rst +++ b/docs/source/telegram.ext.updater.rst @@ -4,4 +4,3 @@ Updater .. autoclass:: telegram.ext.Updater :members: :show-inheritance: - :special-members: __repr__ diff --git a/telegram/ext/_defaults.py b/telegram/ext/_defaults.py index 33eaae09339..845793680d9 100644 --- a/telegram/ext/_defaults.py +++ b/telegram/ext/_defaults.py @@ -126,7 +126,7 @@ def __hash__(self) -> int: def __eq__(self, other: object) -> bool: """Defines equality condition for the :class:`Defaults` object. - Two objects of this class are considered to be equal if their all parameters + Two objects of this class are considered to be equal if all their parameters are identical. Returns: diff --git a/telegram/ext/_jobqueue.py b/telegram/ext/_jobqueue.py index 90098c04264..deea1c302e9 100644 --- a/telegram/ext/_jobqueue.py +++ b/telegram/ext/_jobqueue.py @@ -779,8 +779,9 @@ def __init__( self._job = cast("APSJob", None) # skipcq: PTC-W0052 def __getattr__(self, item: str) -> object: - """Overrides :py:meth:`object.__getattr__` to get specific attribute of - object :class:`telegram.ext.Job` object if exists. + """Overrides :py:meth:`object.__getattr__` to get specific attribute of the + :class:`telegram.ext.Job` object or of its attribute :class:`apscheduler.job.Job`, + if exists. Args: item (:obj:`str`): The name of the attribute. @@ -801,12 +802,12 @@ def __getattr__(self, item: str) -> object: def __eq__(self, other: object) -> bool: """Defines equality condition for the :class:`telegram.ext.Job` object. - Two objects of this class are considered to be equal if their :paramref:`id` - are equal. + Two objects of this class are considered to be equal if their + :class:`id ` are equal. Returns: :obj:`True` if both objects have :paramref:`id` parameters identical. - :obj:`False` otherwise. + :obj:`False` otherwise. """ if isinstance(other, self.__class__): return self.id == other.id diff --git a/telegram/ext/filters.py b/telegram/ext/filters.py index 1c40ef450a1..4c0b3899505 100644 --- a/telegram/ext/filters.py +++ b/telegram/ext/filters.py @@ -185,8 +185,8 @@ def __init__(self, name: Optional[str] = None, data_filter: bool = False): def __and__(self, other: "BaseFilter") -> "BaseFilter": """Defines `AND` bitwise operator for :class:`BaseFilter` object. The combined filter accepts an update only if it is accepted by both filters. - For exampe, filters.PHOTO & filters.CAPTION will only accept messages that contain - both a photo and a caption + For example, ``filters.PHOTO & filters.CAPTION`` will only accept messages that contain + both a photo and a caption. Returns: :obj:`BaseFilter` @@ -196,7 +196,7 @@ def __and__(self, other: "BaseFilter") -> "BaseFilter": def __or__(self, other: "BaseFilter") -> "BaseFilter": """Defines `OR` bitwise operator for :class:`BaseFilter` object. The combined filter accepts an update only if it is accepted by any of the filters. - For example, filters.PHOTO | filters.CAPTION will only accept messages that contain + For example, ``filters.PHOTO | filters.CAPTION`` will only accept messages that contain photo or caption or both. Returns: @@ -207,8 +207,8 @@ def __or__(self, other: "BaseFilter") -> "BaseFilter": def __xor__(self, other: "BaseFilter") -> "BaseFilter": """Defines `XOR` bitwise operator for :class:`BaseFilter` object. The combined filter accepts an update only if it is accepted by any of the filters and - not both of them. For example, filters.PHOTO ^ filters.CAPTION will only accept messages - that contain photo or caption, not both of them. + not both of them. For example, ``filters.PHOTO ^ filters.CAPTION`` will only accept + messages that contain photo or caption, not both of them. Returns: :obj:`BaseFilter` @@ -218,7 +218,7 @@ def __xor__(self, other: "BaseFilter") -> "BaseFilter": def __invert__(self) -> "BaseFilter": """Defines `NOT` bitwise operator for :class:`BaseFilter` object. The combined filter accepts an update only if it is accepted by any of the filters. - For example, ~ filters.PHOTO will only accept messages that do not contain photo. + For example, ``~ filters.PHOTO`` will only accept messages that do not contain photo. Returns: :obj:`BaseFilter` From 00b36454370f8bd47e7985b69240e8ef7e928d68 Mon Sep 17 00:00:00 2001 From: Aditya Date: Thu, 30 Nov 2023 17:29:31 +0530 Subject: [PATCH 07/10] fix equaliy for Bot --- telegram/_bot.py | 8 +++++--- tests/test_bot.py | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/telegram/_bot.py b/telegram/_bot.py index 9a80d7b6c60..50bb6221700 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -363,13 +363,15 @@ def __eq__(self, other: object) -> bool: Returns: :obj:`True` if both attributes :attr:`bot` are equal. :obj:`False` otherwise. """ - if isinstance(other, self.__class__): + if isinstance(other, Bot): return self.bot == other.bot - return False + return super().__eq__(other) def __hash__(self) -> int: """See :meth:`telegram.TelegramObject.__hash__`""" - return hash((self.__class__, self.bot)) + if self._bot_user is None: + return super().__hash__(Bot) + return hash((self.bot, Bot)) def __repr__(self) -> str: """Give a string representation of the bot in the form ``Bot[token=...]``. diff --git a/tests/test_bot.py b/tests/test_bot.py index d6277cf0e40..cd4052eea08 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -316,15 +316,15 @@ async def shutdown(): async def test_equality(self): async with make_bot(token=FALLBACKS[0]["token"]) as a, make_bot( token=FALLBACKS[0]["token"] - ) as b, make_bot(token=FALLBACKS[1]["token"]) as c, Bot(token=FALLBACKS[0]["token"]) as d: + ) as b, Bot(token=FALLBACKS[0]["token"]) as c, make_bot(token=FALLBACKS[1]["token"]) as d: e = Update(123456789) assert a == b assert hash(a) == hash(b) assert a is not b - assert a != c - assert hash(a) != hash(c) + assert a == c + assert hash(a) == hash(c) assert a != d assert hash(a) != hash(d) From 4cea3e435567a69ec1a9710bf3e6957149633ce8 Mon Sep 17 00:00:00 2001 From: Aditya Date: Thu, 30 Nov 2023 18:38:45 +0530 Subject: [PATCH 08/10] fix tests --- telegram/_bot.py | 2 +- tests/test_bot.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/telegram/_bot.py b/telegram/_bot.py index 50bb6221700..db11b6f9758 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -370,7 +370,7 @@ def __eq__(self, other: object) -> bool: def __hash__(self) -> int: """See :meth:`telegram.TelegramObject.__hash__`""" if self._bot_user is None: - return super().__hash__(Bot) + return super().__hash__() return hash((self.bot, Bot)) def __repr__(self) -> str: diff --git a/tests/test_bot.py b/tests/test_bot.py index cd4052eea08..f3d2bfa3521 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -332,6 +332,9 @@ async def test_equality(self): assert a != e assert hash(a) != hash(e) + a._bot_user = None + assert hash(a) != hash(b) + @pytest.mark.parametrize( "attribute", [ From 750c6a9b84cc8655acca4530f908a19b57b354e5 Mon Sep 17 00:00:00 2001 From: Aditya Date: Sat, 9 Dec 2023 17:51:27 +0530 Subject: [PATCH 09/10] tests --- tests/test_bot.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_bot.py b/tests/test_bot.py index f3d2bfa3521..4ef7f6ebf88 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -318,6 +318,7 @@ async def test_equality(self): token=FALLBACKS[0]["token"] ) as b, Bot(token=FALLBACKS[0]["token"]) as c, make_bot(token=FALLBACKS[1]["token"]) as d: e = Update(123456789) + f = Bot(token=FALLBACKS[0]["token"]) assert a == b assert hash(a) == hash(b) @@ -332,8 +333,8 @@ async def test_equality(self): assert a != e assert hash(a) != hash(e) - a._bot_user = None - assert hash(a) != hash(b) + # We cant check equality for unintialized Bot object + assert hash(a) != hash(f) @pytest.mark.parametrize( "attribute", From 435a419aa01c9f9084a74174ac157d436abbe3f1 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Sun, 10 Dec 2023 11:27:40 +0100 Subject: [PATCH 10/10] Hide __weakref__ --- docs/source/conf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index f1c68c504c2..27dd879e63d 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -80,7 +80,9 @@ # Show docstring for special members autodoc_default_options = { "special-members": True, - "exclude-members": "__init__", + # For some reason, __weakref__ can not be ignored by using "inherited-members" in all cases + # so we list it here. + "exclude-members": "__init__, __weakref__", } # Fail on warnings & unresolved references etc