diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6f879136b..bc6cf880c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ ci: repos: - repo: https://github.com/psf/black - rev: 23.9.1 + rev: 23.10.1 hooks: - id: black args: @@ -17,7 +17,7 @@ repos: hooks: - id: flake8 - repo: https://github.com/PyCQA/pylint - rev: v3.0.0 + rev: v3.0.1 hooks: - id: pylint files: ^(telegram|examples)/.*\.py$ @@ -35,7 +35,7 @@ repos: - aiolimiter~=1.1.0 - . # this basically does `pip install -e .` - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.5.1 + rev: v1.6.1 hooks: - id: mypy name: mypy-ptb @@ -62,7 +62,7 @@ repos: - cachetools~=5.3.2 - . # this basically does `pip install -e .` - repo: https://github.com/asottile/pyupgrade - rev: v3.13.0 + rev: v3.15.0 hooks: - id: pyupgrade files: ^(telegram|examples|tests|docs)/.*\.py$ @@ -77,7 +77,7 @@ repos: - --diff - --check - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.0.292' + rev: 'v0.1.5' hooks: - id: ruff name: ruff diff --git a/telegram/_menubutton.py b/telegram/_menubutton.py index a83f4038e..ddb99c418 100644 --- a/telegram/_menubutton.py +++ b/telegram/_menubutton.py @@ -55,7 +55,10 @@ class MenuButton(TelegramObject): __slots__ = ("type",) def __init__( - self, type: str, *, api_kwargs: Optional[JSONDict] = None # skipcq: PYL-W0622 + self, + type: str, # skipcq: PYL-W0622 + *, + api_kwargs: Optional[JSONDict] = None, ): # pylint: disable=redefined-builtin super().__init__(api_kwargs=api_kwargs) self.type: str = type diff --git a/telegram/_passport/credentials.py b/telegram/_passport/credentials.py index adcb11f86..b9f012806 100644 --- a/telegram/_passport/credentials.py +++ b/telegram/_passport/credentials.py @@ -471,7 +471,11 @@ class _CredentialsBase(TelegramObject): __slots__ = ("hash", "secret", "file_hash", "data_hash") def __init__( - self, hash: str, secret: str, *, api_kwargs: Optional[JSONDict] = None # skipcq: PYL-W0622 + self, + hash: str, # skipcq: PYL-W0622 + secret: str, + *, + api_kwargs: Optional[JSONDict] = None, ): super().__init__(api_kwargs=api_kwargs) with self._unfrozen(): diff --git a/telegram/ext/_application.py b/telegram/ext/_application.py index 99a5e32f3..5cc4b72c4 100644 --- a/telegram/ext/_application.py +++ b/telegram/ext/_application.py @@ -1086,7 +1086,7 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AsyncContextManager["Applica return await asyncio.create_task(coroutine) # If user uses generator in python 3.12+, Exception will happen and we cannot do # anything about it. (hence the type ignore if mypy is run on python 3.12-) - return await coroutine # type: ignore + return await coroutine # type: ignore[misc] except Exception as exception: if isinstance(exception, ApplicationHandlerStop): warn( @@ -1367,7 +1367,7 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AsyncContextManager["Applica chat_id (:obj:`int`): The chat id to delete. The entry will be deleted even if it is not empty. """ - self._chat_data.pop(chat_id, None) # type: ignore[arg-type] + self._chat_data.pop(chat_id, None) self._chat_ids_to_be_deleted_in_persistence.add(chat_id) def drop_user_data(self, user_id: int) -> None: @@ -1386,7 +1386,7 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AsyncContextManager["Applica user_id (:obj:`int`): The user id to delete. The entry will be deleted even if it is not empty. """ - self._user_data.pop(user_id, None) # type: ignore[arg-type] + self._user_data.pop(user_id, None) self._user_ids_to_be_deleted_in_persistence.add(user_id) def migrate_chat_data( diff --git a/telegram/ext/_applicationbuilder.py b/telegram/ext/_applicationbuilder.py index 05806f233..664989b18 100644 --- a/telegram/ext/_applicationbuilder.py +++ b/telegram/ext/_applicationbuilder.py @@ -51,6 +51,7 @@ from telegram.request._httpxrequest import HTTPXRequest from telegram.warnings import PTBDeprecationWarning if TYPE_CHECKING: + from telegram import Update from telegram.ext import BasePersistence, BaseRateLimiter, CallbackContext, Defaults from telegram.ext._utils.types import RLARGS @@ -197,7 +198,7 @@ class ApplicationBuilder(Generic[BT, CCT, UD, CD, BD, JQ]): self._arbitrary_callback_data: Union[DefaultValue[bool], int] = DEFAULT_FALSE self._local_mode: DVType[bool] = DEFAULT_FALSE self._bot: DVInput[Bot] = DEFAULT_NONE - self._update_queue: DVType[Queue] = DefaultValue(Queue()) + self._update_queue: DVType[Queue[Union[Update, object]]] = DefaultValue(Queue()) try: self._job_queue: ODVInput[JobQueue] = DefaultValue(JobQueue()) @@ -271,7 +272,7 @@ class ApplicationBuilder(Generic[BT, CCT, UD, CD, BD, JQ]): arbitrary_callback_data=DefaultValue.get_value(self._arbitrary_callback_data), request=self._build_request(get_updates=False), get_updates_request=self._build_request(get_updates=True), - rate_limiter=DefaultValue.get_value(self._rate_limiter), + rate_limiter=DefaultValue.get_value(self._rate_limiter), # type: ignore[arg-type] local_mode=DefaultValue.get_value(self._local_mode), ) @@ -316,7 +317,7 @@ class ApplicationBuilder(Generic[BT, CCT, UD, CD, BD, JQ]): application: Application[ BT, CCT, UD, CD, BD, JQ - ] = DefaultValue.get_value( # pylint: disable=not-callable + ] = DefaultValue.get_value( # type: ignore[operator] # pylint: disable=not-callable self._application_class )( bot=bot, @@ -324,7 +325,7 @@ class ApplicationBuilder(Generic[BT, CCT, UD, CD, BD, JQ]): updater=updater, update_processor=self._update_processor, job_queue=job_queue, - persistence=persistence, + persistence=persistence, # type: ignore[arg-type] context_types=DefaultValue.get_value(self._context_types), post_init=self._post_init, post_shutdown=self._post_shutdown, @@ -333,12 +334,12 @@ class ApplicationBuilder(Generic[BT, CCT, UD, CD, BD, JQ]): ) if job_queue is not None: - job_queue.set_application(application) # type: ignore[arg-type] + job_queue.set_application(application) # type: ignore[arg-type, union-attr] if persistence is not None: # This raises an exception if persistence.store_data.callback_data is True # but self.bot is not an instance of ExtBot - so no need to check that later on - persistence.set_bot(bot) + persistence.set_bot(bot) # type: ignore[union-attr] return application diff --git a/telegram/ext/_callbackcontext.py b/telegram/ext/_callbackcontext.py index ae6011966..bf5922b32 100644 --- a/telegram/ext/_callbackcontext.py +++ b/telegram/ext/_callbackcontext.py @@ -236,11 +236,13 @@ class CallbackContext(Generic[BT, UD, CD, BD]): await self.application.persistence.refresh_bot_data(self.bot_data) if self.application.persistence.store_data.chat_data and self._chat_id is not None: await self.application.persistence.refresh_chat_data( - chat_id=self._chat_id, chat_data=self.chat_data # type: ignore[arg-type] + chat_id=self._chat_id, + chat_data=self.chat_data, # type: ignore[arg-type] ) if self.application.persistence.store_data.user_data and self._user_id is not None: await self.application.persistence.refresh_user_data( - user_id=self._user_id, user_data=self.user_data # type: ignore[arg-type] + user_id=self._user_id, + user_data=self.user_data, # type: ignore[arg-type] ) def drop_callback_data(self, callback_query: CallbackQuery) -> None: diff --git a/telegram/ext/_picklepersistence.py b/telegram/ext/_picklepersistence.py index 928cb8968..9714f3035 100644 --- a/telegram/ext/_picklepersistence.py +++ b/telegram/ext/_picklepersistence.py @@ -492,7 +492,7 @@ class PicklePersistence(BasePersistence[UD, CD, BD]): """ if self.chat_data is None: return - self.chat_data.pop(chat_id, None) # type: ignore[arg-type] + self.chat_data.pop(chat_id, None) if not self.on_flush: if not self.single_file: @@ -511,7 +511,7 @@ class PicklePersistence(BasePersistence[UD, CD, BD]): """ if self.user_data is None: return - self.user_data.pop(user_id, None) # type: ignore[arg-type] + self.user_data.pop(user_id, None) if not self.on_flush: if not self.single_file: diff --git a/telegram/ext/_utils/trackingdict.py b/telegram/ext/_utils/trackingdict.py index 4a525a409..2cf986092 100644 --- a/telegram/ext/_utils/trackingdict.py +++ b/telegram/ext/_utils/trackingdict.py @@ -99,7 +99,9 @@ class TrackingDict(UserDict, Generic[_KT, _VT]): # Mypy seems a bit inconsistent about what it wants as types for `default` and return value # so we just ignore a bit def pop( # type: ignore[override] - self, key: _KT, default: _VT = DEFAULT_NONE # type: ignore[assignment] + self, + key: _KT, + default: _VT = DEFAULT_NONE, # type: ignore[assignment] ) -> _VT: if key in self: self.__track_write(key)