diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b13703376..05394b6fa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ ci: repos: - repo: https://github.com/psf/black - rev: 22.12.0 + rev: 23.1.0 hooks: - id: black args: @@ -20,7 +20,7 @@ repos: hooks: - id: flake8 - repo: https://github.com/PyCQA/pylint - rev: v2.15.9 + rev: v2.16.1 hooks: - id: pylint files: ^(telegram|examples)/.*\.py$ @@ -80,7 +80,7 @@ repos: - --diff - --check - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: 'v0.0.222' + rev: 'v0.0.243' hooks: - id: ruff name: ruff diff --git a/docs/auxil/admonition_inserter.py b/docs/auxil/admonition_inserter.py index 31634277a..870d02f0a 100644 --- a/docs/auxil/admonition_inserter.py +++ b/docs/auxil/admonition_inserter.py @@ -106,7 +106,6 @@ class AdmonitionInserter: # docs.auxil.sphinx_hooks.autodoc_process_docstring() for admonition_type in self.ALL_ADMONITION_TYPES: - # If there is no admonition of the given type for the given class or method, # continue to the next admonition type, maybe the class/method is listed there. if obj not in self.admonitions[admonition_type]: @@ -258,7 +257,6 @@ class AdmonitionInserter: for cls, method_names in self.METHOD_NAMES_FOR_BOT_AND_APPBUILDER.items(): for method_name in method_names: - sig = inspect.signature(getattr(cls, method_name)) ret_annot = sig.return_annotation @@ -301,16 +299,13 @@ class AdmonitionInserter: # inspect methods of all telegram classes for return statements that indicate # that this given method is a shortcut for a Bot method for class_name, cls in inspect.getmembers(telegram, predicate=inspect.isclass): - # no need to inspect Bot's own methods, as Bot can't have shortcuts in Bot if cls is telegram.Bot: continue for method_name, method in _iter_own_public_methods(cls): - # .getsourcelines() returns a tuple. Item [1] is an int for line in inspect.getsourcelines(method)[0]: - if not (bot_method_match := bot_method_pattern.search(line)): continue @@ -412,7 +407,6 @@ class AdmonitionInserter: admonition_for_class = {} for cls, attrs in attrs_or_methods_for_class.items(): - if cls is telegram.ext.ApplicationBuilder: # ApplicationBuilder is only used in and returned from its own methods, # so its page needs no admonitions. @@ -472,7 +466,6 @@ class AdmonitionInserter: **Modifies dictionary in place.** """ for cls in self._resolve_arg(arg): - # When trying to resolve an argument from args or return annotation, # the method _resolve_arg returns None if nothing could be resolved. # Also, if class was resolved correctly, "telegram" will definitely be in its str(). @@ -549,7 +542,6 @@ class AdmonitionInserter: # For some reason "InlineQueryResult", "InputMedia" & some others are currently not # recognized as ForwardRefs and are identified as plain strings. elif isinstance(arg, str): - # args like "ApplicationBuilder[BT, CCT, UD, CD, BD, JQ]" can be recognized as strings. # Remove whatever is in the square brackets because it doesn't need to be parsed. arg = re.sub(r"\[.+]", "", arg) diff --git a/telegram/_files/inputmedia.py b/telegram/_files/inputmedia.py index 3c6946158..edaacfc6e 100644 --- a/telegram/_files/inputmedia.py +++ b/telegram/_files/inputmedia.py @@ -391,7 +391,6 @@ class InputMediaVideo(InputMedia): *, api_kwargs: JSONDict = None, ): - if isinstance(media, Video): width = width if width is not None else media.width height = height if height is not None else media.height diff --git a/telegram/_inline/inlinequeryresultarticle.py b/telegram/_inline/inlinequeryresultarticle.py index 9b803ac09..d602cf1c1 100644 --- a/telegram/_inline/inlinequeryresultarticle.py +++ b/telegram/_inline/inlinequeryresultarticle.py @@ -99,7 +99,6 @@ class InlineQueryResultArticle(InlineQueryResult): *, api_kwargs: JSONDict = None, ): - # Required super().__init__(InlineQueryResultType.ARTICLE, id, api_kwargs=api_kwargs) with self._unfrozen(): diff --git a/telegram/_inline/inlinequeryresultaudio.py b/telegram/_inline/inlinequeryresultaudio.py index 5be232084..23df99932 100644 --- a/telegram/_inline/inlinequeryresultaudio.py +++ b/telegram/_inline/inlinequeryresultaudio.py @@ -113,7 +113,6 @@ class InlineQueryResultAudio(InlineQueryResult): *, api_kwargs: JSONDict = None, ): - # Required super().__init__(InlineQueryResultType.AUDIO, id, api_kwargs=api_kwargs) with self._unfrozen(): diff --git a/telegram/_inline/inlinequeryresultgif.py b/telegram/_inline/inlinequeryresultgif.py index 7c4f80dc7..c7e6d63b7 100644 --- a/telegram/_inline/inlinequeryresultgif.py +++ b/telegram/_inline/inlinequeryresultgif.py @@ -130,7 +130,6 @@ class InlineQueryResultGif(InlineQueryResult): *, api_kwargs: JSONDict = None, ): - # Required super().__init__(InlineQueryResultType.GIF, id, api_kwargs=api_kwargs) with self._unfrozen(): diff --git a/telegram/_inline/inlinequeryresultmpeg4gif.py b/telegram/_inline/inlinequeryresultmpeg4gif.py index c9a979a19..b16a60acb 100644 --- a/telegram/_inline/inlinequeryresultmpeg4gif.py +++ b/telegram/_inline/inlinequeryresultmpeg4gif.py @@ -133,7 +133,6 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): *, api_kwargs: JSONDict = None, ): - # Required super().__init__(InlineQueryResultType.MPEG4GIF, id, api_kwargs=api_kwargs) with self._unfrozen(): diff --git a/telegram/_inline/inlinequeryresultvenue.py b/telegram/_inline/inlinequeryresultvenue.py index 216cc142f..853a3d9c7 100644 --- a/telegram/_inline/inlinequeryresultvenue.py +++ b/telegram/_inline/inlinequeryresultvenue.py @@ -125,7 +125,6 @@ class InlineQueryResultVenue(InlineQueryResult): *, api_kwargs: JSONDict = None, ): - # Required super().__init__(InlineQueryResultType.VENUE, id, api_kwargs=api_kwargs) with self._unfrozen(): diff --git a/telegram/_inline/inlinequeryresultvideo.py b/telegram/_inline/inlinequeryresultvideo.py index 972e319c3..5079248dd 100644 --- a/telegram/_inline/inlinequeryresultvideo.py +++ b/telegram/_inline/inlinequeryresultvideo.py @@ -141,7 +141,6 @@ class InlineQueryResultVideo(InlineQueryResult): *, api_kwargs: JSONDict = None, ): - # Required super().__init__(InlineQueryResultType.VIDEO, id, api_kwargs=api_kwargs) with self._unfrozen(): diff --git a/telegram/_inline/inlinequeryresultvoice.py b/telegram/_inline/inlinequeryresultvoice.py index 6d5263724..deddccd6d 100644 --- a/telegram/_inline/inlinequeryresultvoice.py +++ b/telegram/_inline/inlinequeryresultvoice.py @@ -111,7 +111,6 @@ class InlineQueryResultVoice(InlineQueryResult): *, api_kwargs: JSONDict = None, ): - # Required super().__init__(InlineQueryResultType.VOICE, id, api_kwargs=api_kwargs) with self._unfrozen(): diff --git a/telegram/_message.py b/telegram/_message.py index a91896d3f..8e7097f59 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -3241,10 +3241,10 @@ class Message(TelegramObject): html_text = "" last_offset = 0 - sorted_entities = sorted(entities.items(), key=(lambda item: item[0].offset)) + sorted_entities = sorted(entities.items(), key=lambda item: item[0].offset) parsed_entities = [] - for (entity, text) in sorted_entities: + for entity, text in sorted_entities: if entity not in parsed_entities: nested_entities = { e: t @@ -3426,10 +3426,10 @@ class Message(TelegramObject): markdown_text = "" last_offset = 0 - sorted_entities = sorted(entities.items(), key=(lambda item: item[0].offset)) + sorted_entities = sorted(entities.items(), key=lambda item: item[0].offset) parsed_entities = [] - for (entity, text) in sorted_entities: + for entity, text in sorted_entities: if entity not in parsed_entities: nested_entities = { e: t diff --git a/telegram/_telegramobject.py b/telegram/_telegramobject.py index afcf15642..753e216ab 100644 --- a/telegram/_telegramobject.py +++ b/telegram/_telegramobject.py @@ -289,7 +289,6 @@ class TelegramObject: frozen = state.pop("_frozen", False) for key, val in state.items(): - try: setattr(self, key, val) except AttributeError: @@ -402,7 +401,6 @@ class TelegramObject: data = {} for key in self._get_attrs_names(include_private=include_private): - value = getattr(self, key, None) if value is not None: if recursive and hasattr(value, "to_dict"): diff --git a/telegram/ext/_applicationbuilder.py b/telegram/ext/_applicationbuilder.py index b146b0abc..75fac4d62 100644 --- a/telegram/ext/_applicationbuilder.py +++ b/telegram/ext/_applicationbuilder.py @@ -221,12 +221,12 @@ class ApplicationBuilder(Generic[BT, CCT, UD, CD, BD, JQ]): DefaultValue.get_value(getattr(self, f"{prefix}connection_pool_size")) or 256 ) - timeouts = dict( - connect_timeout=getattr(self, f"{prefix}connect_timeout"), - read_timeout=getattr(self, f"{prefix}read_timeout"), - write_timeout=getattr(self, f"{prefix}write_timeout"), - pool_timeout=getattr(self, f"{prefix}pool_timeout"), - ) + timeouts = { + "connect_timeout": getattr(self, f"{prefix}connect_timeout"), + "read_timeout": getattr(self, f"{prefix}read_timeout"), + "write_timeout": getattr(self, f"{prefix}write_timeout"), + "pool_timeout": getattr(self, f"{prefix}pool_timeout"), + } # Get timeouts that were actually set- effective_timeouts = { key: value for key, value in timeouts.items() if not isinstance(value, DefaultValue) diff --git a/telegram/ext/_conversationhandler.py b/telegram/ext/_conversationhandler.py index 04948b0c5..aa36868e9 100644 --- a/telegram/ext/_conversationhandler.py +++ b/telegram/ext/_conversationhandler.py @@ -292,6 +292,7 @@ class ConversationHandler(BaseHandler[Update, CCT]): WAITING: ClassVar[int] = -3 """:obj:`int`: Used as a constant to handle state when a conversation is still waiting on the previous :attr:`block=False ` handler to finish.""" + # pylint: disable=super-init-not-called def __init__( self, diff --git a/telegram/ext/_messagehandler.py b/telegram/ext/_messagehandler.py index e2ed9ac77..0deb2efe0 100644 --- a/telegram/ext/_messagehandler.py +++ b/telegram/ext/_messagehandler.py @@ -80,7 +80,6 @@ class MessageHandler(BaseHandler[Update, CCT]): callback: HandlerCallback[Update, CCT, RT], block: DVType[bool] = DEFAULT_TRUE, ): - super().__init__(callback, block=block) self.filters: filters_module.BaseFilter = ( filters if filters is not None else filters_module.ALL diff --git a/telegram/ext/_prefixhandler.py b/telegram/ext/_prefixhandler.py index ef42c6b91..5026457c6 100644 --- a/telegram/ext/_prefixhandler.py +++ b/telegram/ext/_prefixhandler.py @@ -130,7 +130,6 @@ class PrefixHandler(BaseHandler[Update, CCT]): filters: filters_module.BaseFilter = None, block: DVType[bool] = DEFAULT_TRUE, ): - super().__init__(callback=callback, block=block) if isinstance(prefix, str): diff --git a/telegram/ext/_updater.py b/telegram/ext/_updater.py index e4207cef6..7f0f376af 100644 --- a/telegram/ext/_updater.py +++ b/telegram/ext/_updater.py @@ -301,7 +301,6 @@ class Updater(AsyncContextManager["Updater"]): ready: asyncio.Event, error_callback: Optional[Callable[[TelegramError], None]], ) -> None: - self._logger.debug("Updater started (polling)") # the bootstrapping phase does two things: diff --git a/telegram/request/_httpxrequest.py b/telegram/request/_httpxrequest.py index 00df85eed..f67277ab3 100644 --- a/telegram/request/_httpxrequest.py +++ b/telegram/request/_httpxrequest.py @@ -117,13 +117,13 @@ class HTTPXRequest(BaseRequest): http1 = http_version == "1.1" - self._client_kwargs = dict( - timeout=timeout, - proxies=proxy_url, - limits=limits, - http1=http1, - http2=not http1, - ) + self._client_kwargs = { + "timeout": timeout, + "proxies": proxy_url, + "limits": limits, + "http1": http1, + "http2": not http1, + } try: self._client = self._build_client() diff --git a/tests/test_chatinvitelink.py b/tests/test_chatinvitelink.py index a2edfd57e..276b3856f 100644 --- a/tests/test_chatinvitelink.py +++ b/tests/test_chatinvitelink.py @@ -45,7 +45,6 @@ def invite_link(creator): class TestChatInviteLink: - link = "thisialink" creates_join_request = False primary = True diff --git a/tests/test_chatpermissions.py b/tests/test_chatpermissions.py index 7c37d9eec..584506ec6 100644 --- a/tests/test_chatpermissions.py +++ b/tests/test_chatpermissions.py @@ -201,7 +201,6 @@ class TestChatPermissions: assert f != t def test_equality_warning(self, recwarn, chat_permissions): - recwarn.clear() assert chat_permissions == chat_permissions diff --git a/tests/test_conversationhandler.py b/tests/test_conversationhandler.py index ece1e7ce2..3e3e01033 100644 --- a/tests/test_conversationhandler.py +++ b/tests/test_conversationhandler.py @@ -2053,7 +2053,6 @@ class TestConversationHandler: await app.stop() async def test_no_timeout_on_end(self, app, user1): - conv_handler = ConversationHandler( entry_points=[MessageHandler(filters.ALL, callback=self.start_end)], states={ConversationHandler.TIMEOUT: [TypeHandler(Update, self.passout2)]}, @@ -2116,7 +2115,6 @@ class TestConversationHandler: async def test_blocking_resolution_order( self, bot, default_block, ch_block, handler_block, ext_bot ): - event = asyncio.Event() async def callback(_, __): diff --git a/tests/test_keyboardbutton.py b/tests/test_keyboardbutton.py index e80012d82..7d508973c 100644 --- a/tests/test_keyboardbutton.py +++ b/tests/test_keyboardbutton.py @@ -131,7 +131,6 @@ class TestKeyboardButton: assert hash(a) == hash(f) def test_equality_warning(self, recwarn, keyboard_button): - recwarn.clear() assert keyboard_button == keyboard_button diff --git a/tests/test_ratelimiter.py b/tests/test_ratelimiter.py index b770de083..1f888f112 100644 --- a/tests/test_ratelimiter.py +++ b/tests/test_ratelimiter.py @@ -199,7 +199,6 @@ class TestAIORateLimiter: @pytest.mark.parametrize("max_retries", [0, 1, 4]) async def test_max_retries(self, bot, max_retries): - bot = ExtBot( token=bot.token, request=self.CountRequest(retry_after=1), diff --git a/tests/test_request.py b/tests/test_request.py index 384d1dadf..0b773d545 100644 --- a/tests/test_request.py +++ b/tests/test_request.py @@ -480,7 +480,6 @@ class TestHTTPXRequest: write_timeout=default_timeouts.write, pool_timeout=default_timeouts.pool, ) as httpx_request: - monkeypatch.setattr(httpx.AsyncClient, "request", make_assertion) await httpx_request.do_request(method="GET", url="URL") @@ -500,7 +499,6 @@ class TestHTTPXRequest: write_timeout=default_timeouts.write, pool_timeout=default_timeouts.pool, ) as httpx_request: - monkeypatch.setattr(httpx.AsyncClient, "request", make_assertion) await httpx_request.do_request( method="GET",