diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 32c3b58de..c29c898e3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,14 +6,14 @@ ci: repos: - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 23.7.0 hooks: - id: black args: - --diff - --check - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 + rev: 6.1.0 hooks: - id: flake8 - repo: https://github.com/PyCQA/pylint @@ -62,7 +62,7 @@ repos: - cachetools~=5.3.1 - . # this basically does `pip install -e .` - repo: https://github.com/asottile/pyupgrade - rev: v3.8.0 + rev: v3.10.1 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.277' + rev: 'v0.0.281' hooks: - id: ruff name: ruff diff --git a/pyproject.toml b/pyproject.toml index 264f8c063..d7e3672a3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ target-version = "py38" show-fixes = true ignore = ["PLR2004", "PLR0911", "PLR0912", "PLR0913", "PLR0915", "PERF203"] select = ["E", "F", "I", "PL", "UP", "RUF", "PTH", "C4", "B", "PIE", "SIM", "RET", "RSE", - "G", "ISC", "PT", "ASYNC", "TCH", "CPY", "SLOT", "PERF",] + "G", "ISC", "PT", "ASYNC", "TCH", "CPY", "SLOT", "PERF", "PYI"] [tool.ruff.per-file-ignores] "tests/*.py" = ["B018"] diff --git a/telegram/_bot.py b/telegram/_bot.py index 47ba0bbd8..1a72a05b0 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -2746,7 +2746,7 @@ class Bot(TelegramObject, AsyncContextManager["Bot"]): if callable(results): callable_output = results(current_offset_int) if not callable_output: - effective_results: Sequence["InlineQueryResult"] = [] + effective_results: Sequence[InlineQueryResult] = [] else: effective_results = callable_output # the callback *might* return more results on the next call, so we increment diff --git a/telegram/_botcommandscope.py b/telegram/_botcommandscope.py index c65296529..25017f27e 100644 --- a/telegram/_botcommandscope.py +++ b/telegram/_botcommandscope.py @@ -100,7 +100,7 @@ class BotCommandScope(TelegramObject): if not data: return None - _class_mapping: Dict[str, Type["BotCommandScope"]] = { + _class_mapping: Dict[str, Type[BotCommandScope]] = { cls.DEFAULT: BotCommandScopeDefault, cls.ALL_PRIVATE_CHATS: BotCommandScopeAllPrivateChats, cls.ALL_GROUP_CHATS: BotCommandScopeAllGroupChats, diff --git a/telegram/_chatmember.py b/telegram/_chatmember.py index 598c9cf06..41d8e93f9 100644 --- a/telegram/_chatmember.py +++ b/telegram/_chatmember.py @@ -111,7 +111,7 @@ class ChatMember(TelegramObject): if not data: return None - _class_mapping: Dict[str, Type["ChatMember"]] = { + _class_mapping: Dict[str, Type[ChatMember]] = { cls.OWNER: ChatMemberOwner, cls.ADMINISTRATOR: ChatMemberAdministrator, cls.MEMBER: ChatMemberMember, diff --git a/telegram/_files/file.py b/telegram/_files/file.py index e96860f5f..3a9801520 100644 --- a/telegram/_files/file.py +++ b/telegram/_files/file.py @@ -99,7 +99,7 @@ class File(TelegramObject): self.file_size: Optional[int] = file_size self.file_path: Optional[str] = file_path - self._credentials: Optional["FileCredentials"] = None + self._credentials: Optional[FileCredentials] = None self._id_attrs = (self.file_unique_id,) diff --git a/telegram/_menubutton.py b/telegram/_menubutton.py index 0bc79c243..a83f4038e 100644 --- a/telegram/_menubutton.py +++ b/telegram/_menubutton.py @@ -85,7 +85,7 @@ class MenuButton(TelegramObject): if not data and cls is MenuButton: return None - _class_mapping: Dict[str, Type["MenuButton"]] = { + _class_mapping: Dict[str, Type[MenuButton]] = { cls.COMMANDS: MenuButtonCommands, cls.WEB_APP: MenuButtonWebApp, cls.DEFAULT: MenuButtonDefault, diff --git a/telegram/_message.py b/telegram/_message.py index 5492b6c2e..6f6118adf 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -766,8 +766,8 @@ class Message(TelegramObject): self.edit_date: Optional[datetime.datetime] = edit_date self.has_protected_content: Optional[bool] = has_protected_content self.text: Optional[str] = text - self.entities: Tuple["MessageEntity", ...] = parse_sequence_arg(entities) - self.caption_entities: Tuple["MessageEntity", ...] = parse_sequence_arg(caption_entities) + self.entities: Tuple[MessageEntity, ...] = parse_sequence_arg(entities) + self.caption_entities: Tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities) self.audio: Optional[Audio] = audio self.game: Optional[Game] = game self.document: Optional[Document] = document diff --git a/telegram/_passport/credentials.py b/telegram/_passport/credentials.py index 498a6dca7..adcb11f86 100644 --- a/telegram/_passport/credentials.py +++ b/telegram/_passport/credentials.py @@ -154,7 +154,7 @@ class EncryptedCredentials(TelegramObject): self._id_attrs = (self.data, self.hash, self.secret) self._decrypted_secret: Optional[str] = None - self._decrypted_data: Optional["Credentials"] = None + self._decrypted_data: Optional[Credentials] = None self._freeze() @@ -442,8 +442,8 @@ class SecureValue(TelegramObject): self.front_side: Optional[FileCredentials] = front_side self.reverse_side: Optional[FileCredentials] = reverse_side self.selfie: Optional[FileCredentials] = selfie - self.files: Tuple["FileCredentials", ...] = parse_sequence_arg(files) - self.translation: Tuple["FileCredentials", ...] = parse_sequence_arg(translation) + self.files: Tuple[FileCredentials, ...] = parse_sequence_arg(files) + self.translation: Tuple[FileCredentials, ...] = parse_sequence_arg(translation) self._freeze() diff --git a/telegram/_payment/shippingoption.py b/telegram/_payment/shippingoption.py index 4526f68c2..2fea44460 100644 --- a/telegram/_payment/shippingoption.py +++ b/telegram/_payment/shippingoption.py @@ -68,7 +68,7 @@ class ShippingOption(TelegramObject): self.id: str = id # pylint: disable=invalid-name self.title: str = title - self.prices: Tuple["LabeledPrice", ...] = parse_sequence_arg(prices) + self.prices: Tuple[LabeledPrice, ...] = parse_sequence_arg(prices) self._id_attrs = (self.id,) diff --git a/telegram/_telegramobject.py b/telegram/_telegramobject.py index fbc3a2840..78b8a35e6 100644 --- a/telegram/_telegramobject.py +++ b/telegram/_telegramobject.py @@ -106,7 +106,7 @@ class TelegramObject: # classes than classes with arguments. self._frozen: bool = False self._id_attrs: Tuple[object, ...] = () - self._bot: Optional["Bot"] = None + self._bot: Optional[Bot] = None # We don't do anything with api_kwargs here - see docstring of _apply_api_kwargs self.api_kwargs: Mapping[str, Any] = MappingProxyType(api_kwargs or {}) diff --git a/telegram/_update.py b/telegram/_update.py index 323b664e9..3cbf6a4a6 100644 --- a/telegram/_update.py +++ b/telegram/_update.py @@ -271,8 +271,8 @@ class Update(TelegramObject): self.chat_member: Optional[ChatMemberUpdated] = chat_member self.chat_join_request: Optional[ChatJoinRequest] = chat_join_request - self._effective_user: Optional["User"] = None - self._effective_chat: Optional["Chat"] = None + self._effective_user: Optional[User] = None + self._effective_chat: Optional[Chat] = None self._effective_message: Optional[Message] = None self._id_attrs = (self.update_id,) diff --git a/telegram/ext/_application.py b/telegram/ext/_application.py index 14bb45c8c..3567f8ac3 100644 --- a/telegram/ext/_application.py +++ b/telegram/ext/_application.py @@ -294,7 +294,7 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AsyncContextManager["Applica ) self.bot: BT = bot - self.update_queue: "asyncio.Queue[object]" = update_queue + self.update_queue: asyncio.Queue[object] = update_queue self.context_types: ContextTypes[CCT, UD, CD, BD] = context_types self.updater: Optional[Updater] = updater self.handlers: Dict[int, List[BaseHandler[Any, CCT]]] = {} @@ -302,13 +302,13 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AsyncContextManager["Applica HandlerCallback[object, CCT, None], Union[bool, DefaultValue[bool]] ] = {} self.post_init: Optional[ - Callable[["Application[BT, CCT, UD, CD, BD, JQ]"], Coroutine[Any, Any, None]] + Callable[[Application[BT, CCT, UD, CD, BD, JQ]], Coroutine[Any, Any, None]] ] = post_init self.post_shutdown: Optional[ - Callable[["Application[BT, CCT, UD, CD, BD, JQ]"], Coroutine[Any, Any, None]] + Callable[[Application[BT, CCT, UD, CD, BD, JQ]], Coroutine[Any, Any, None]] ] = post_shutdown self.post_stop: Optional[ - Callable[["Application[BT, CCT, UD, CD, BD, JQ]"], Coroutine[Any, Any, None]] + Callable[[Application[BT, CCT, UD, CD, BD, JQ]], Coroutine[Any, Any, None]] ] = post_stop self._update_processor = update_processor self.bot_data: BD = self.context_types.bot_data() @@ -1012,7 +1012,7 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AsyncContextManager["Applica # but by passing `is_error_handler=True` from `process_error`, we can make sure that we # get at most one recursion of the user calls `create_task` manually with an error handler # function - task: "asyncio.Task[RT]" = asyncio.create_task( + task: asyncio.Task[RT] = asyncio.create_task( self.__create_task_callback( coroutine=coroutine, update=update, is_error_handler=is_error_handler ), @@ -1671,7 +1671,7 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AsyncContextManager["Applica update: Optional[object], error: Exception, job: Optional["Job[CCT]"] = None, - coroutine: _ErrorCoroType[RT] = None, # noqa: RUF013 + coroutine: _ErrorCoroType[RT] = None, ) -> bool: """Processes an error by passing it to all error handlers registered with :meth:`add_error_handler`. If one of the error handlers raises diff --git a/telegram/ext/_applicationbuilder.py b/telegram/ext/_applicationbuilder.py index 05278a6d0..b636f6a23 100644 --- a/telegram/ext/_applicationbuilder.py +++ b/telegram/ext/_applicationbuilder.py @@ -171,42 +171,42 @@ class ApplicationBuilder(Generic[BT, CCT, UD, CD, BD, JQ]): self._read_timeout: ODVInput[float] = DEFAULT_NONE self._write_timeout: ODVInput[float] = DEFAULT_NONE self._pool_timeout: ODVInput[float] = DEFAULT_NONE - self._request: DVInput["BaseRequest"] = DEFAULT_NONE + self._request: DVInput[BaseRequest] = DEFAULT_NONE self._get_updates_connection_pool_size: DVInput[int] = DEFAULT_NONE self._get_updates_proxy_url: DVInput[str] = DEFAULT_NONE self._get_updates_connect_timeout: ODVInput[float] = DEFAULT_NONE self._get_updates_read_timeout: ODVInput[float] = DEFAULT_NONE self._get_updates_write_timeout: ODVInput[float] = DEFAULT_NONE self._get_updates_pool_timeout: ODVInput[float] = DEFAULT_NONE - self._get_updates_request: DVInput["BaseRequest"] = DEFAULT_NONE + self._get_updates_request: DVInput[BaseRequest] = DEFAULT_NONE self._get_updates_http_version: DVInput[str] = DefaultValue("1.1") self._private_key: ODVInput[bytes] = DEFAULT_NONE self._private_key_password: ODVInput[bytes] = DEFAULT_NONE - self._defaults: ODVInput["Defaults"] = DEFAULT_NONE + self._defaults: ODVInput[Defaults] = DEFAULT_NONE 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()) try: - self._job_queue: ODVInput["JobQueue"] = DefaultValue(JobQueue()) + self._job_queue: ODVInput[JobQueue] = DefaultValue(JobQueue()) except RuntimeError as exc: if "PTB must be installed via" not in str(exc): raise exc self._job_queue = DEFAULT_NONE - self._persistence: ODVInput["BasePersistence"] = DEFAULT_NONE + self._persistence: ODVInput[BasePersistence] = DEFAULT_NONE self._context_types: DVType[ContextTypes] = DefaultValue(ContextTypes()) self._application_class: DVType[Type[Application]] = DefaultValue(Application) self._application_kwargs: Dict[str, object] = {} - self._update_processor: "BaseUpdateProcessor" = SimpleUpdateProcessor( + self._update_processor: BaseUpdateProcessor = SimpleUpdateProcessor( max_concurrent_updates=1 ) self._updater: ODVInput[Updater] = DEFAULT_NONE self._post_init: Optional[Callable[[Application], Coroutine[Any, Any, None]]] = None self._post_shutdown: Optional[Callable[[Application], Coroutine[Any, Any, None]]] = None self._post_stop: Optional[Callable[[Application], Coroutine[Any, Any, None]]] = None - self._rate_limiter: ODVInput["BaseRateLimiter"] = DEFAULT_NONE + self._rate_limiter: ODVInput[BaseRateLimiter] = DEFAULT_NONE self._http_version: DVInput[str] = DefaultValue("1.1") def _build_request(self, get_updates: bool) -> BaseRequest: diff --git a/telegram/ext/_callbackcontext.py b/telegram/ext/_callbackcontext.py index d209930b1..ae6011966 100644 --- a/telegram/ext/_callbackcontext.py +++ b/telegram/ext/_callbackcontext.py @@ -144,9 +144,9 @@ class CallbackContext(Generic[BT, UD, CD, BD]): self.args: Optional[List[str]] = None self.matches: Optional[List[Match[str]]] = None self.error: Optional[Exception] = None - self.job: Optional["Job[CCT]"] = None + self.job: Optional[Job[CCT]] = None self.coroutine: Optional[ - Union[Generator[Optional["Future[object]"], None, Any], Awaitable[Any]] + Union[Generator[Optional[Future[object]], None, Any], Awaitable[Any]] ] = None @property diff --git a/telegram/ext/_conversationhandler.py b/telegram/ext/_conversationhandler.py index 7571b75fd..976135e54 100644 --- a/telegram/ext/_conversationhandler.py +++ b/telegram/ext/_conversationhandler.py @@ -339,10 +339,10 @@ class ConversationHandler(BaseHandler[Update, CCT]): # if conversation_timeout is used, this dict is used to schedule a job which runs when the # conv has timed out. - self.timeout_jobs: Dict[ConversationKey, "Job[Any]"] = {} + self.timeout_jobs: Dict[ConversationKey, Job[Any]] = {} self._timeout_jobs_lock = asyncio.Lock() self._conversations: ConversationDict = {} - self._child_conversations: Set["ConversationHandler"] = set() + self._child_conversations: Set[ConversationHandler] = set() if persistent and not self.name: raise ValueError("Conversations can't be persistent when handler is unnamed.") diff --git a/telegram/ext/_jobqueue.py b/telegram/ext/_jobqueue.py index d6be175fa..99c5b5864 100644 --- a/telegram/ext/_jobqueue.py +++ b/telegram/ext/_jobqueue.py @@ -91,7 +91,7 @@ class JobQueue(Generic[CCT]): '"python-telegram-bot[job-queue]"`.' ) - self._application: "Optional[weakref.ReferenceType[Application]]" = None + self._application: Optional[weakref.ReferenceType[Application]] = None self._executor = AsyncIOExecutor() self.scheduler: AsyncIOScheduler = AsyncIOScheduler( timezone=pytz.utc, executors={"default": self._executor} diff --git a/telegram/ext/_updater.py b/telegram/ext/_updater.py index b876bbcd0..5c0da22a7 100644 --- a/telegram/ext/_updater.py +++ b/telegram/ext/_updater.py @@ -113,7 +113,7 @@ class Updater(AsyncContextManager["Updater"]): update_queue: "asyncio.Queue[object]", ): self.bot: Bot = bot - self.update_queue: "asyncio.Queue[object]" = update_queue + self.update_queue: asyncio.Queue[object] = update_queue self._last_update_id = 0 self._running = False diff --git a/tests/_files/test_animation.py b/tests/_files/test_animation.py index 8aeed67cd..8f32386be 100644 --- a/tests/_files/test_animation.py +++ b/tests/_files/test_animation.py @@ -156,7 +156,7 @@ class TestAnimationWithoutRequest(TestAnimationBase): async def test_send_animation_custom_filename(self, bot, chat_id, animation_file, monkeypatch): async def make_assertion(url, request_data: RequestData, *args, **kwargs): - return list(request_data.multipart_data.values())[0][0] == "custom_filename" + return next(iter(request_data.multipart_data.values()))[0] == "custom_filename" monkeypatch.setattr(bot.request, "post", make_assertion) assert await bot.send_animation(chat_id, animation_file, filename="custom_filename") diff --git a/tests/_files/test_audio.py b/tests/_files/test_audio.py index fe7cc2774..574650f1a 100644 --- a/tests/_files/test_audio.py +++ b/tests/_files/test_audio.py @@ -176,7 +176,7 @@ class TestAudioWithoutRequest(TestAudioBase): async def test_send_audio_custom_filename(self, bot, chat_id, audio_file, monkeypatch): async def make_assertion(url, request_data: RequestData, *args, **kwargs): - return list(request_data.multipart_data.values())[0][0] == "custom_filename" + return next(iter(request_data.multipart_data.values()))[0] == "custom_filename" monkeypatch.setattr(bot.request, "post", make_assertion) assert await bot.send_audio(chat_id, audio_file, filename="custom_filename") diff --git a/tests/_files/test_photo.py b/tests/_files/test_photo.py index 6419ff7b3..1bf5d914c 100644 --- a/tests/_files/test_photo.py +++ b/tests/_files/test_photo.py @@ -162,7 +162,7 @@ class TestPhotoWithoutRequest(TestPhotoBase): async def test_send_photo_custom_filename(self, bot, chat_id, photo_file, monkeypatch): async def make_assertion(url, request_data: RequestData, *args, **kwargs): - return list(request_data.multipart_data.values())[0][0] == "custom_filename" + return next(iter(request_data.multipart_data.values()))[0] == "custom_filename" monkeypatch.setattr(bot.request, "post", make_assertion) assert await bot.send_photo(chat_id, photo_file, filename="custom_filename") diff --git a/tests/_files/test_video.py b/tests/_files/test_video.py index 5722cf753..233d04b3c 100644 --- a/tests/_files/test_video.py +++ b/tests/_files/test_video.py @@ -189,7 +189,7 @@ class TestVideoWithoutRequest(TestVideoBase): async def test_send_video_custom_filename(self, bot, chat_id, video_file, monkeypatch): async def make_assertion(url, request_data: RequestData, *args, **kwargs): - return list(request_data.multipart_data.values())[0][0] == "custom_filename" + return next(iter(request_data.multipart_data.values()))[0] == "custom_filename" monkeypatch.setattr(bot.request, "post", make_assertion) diff --git a/tests/_files/test_videonote.py b/tests/_files/test_videonote.py index 5973e797f..48945a338 100644 --- a/tests/_files/test_videonote.py +++ b/tests/_files/test_videonote.py @@ -169,7 +169,7 @@ class TestVideoNoteWithoutRequest(TestVideoNoteBase): self, bot, chat_id, video_note_file, monkeypatch ): async def make_assertion(url, request_data: RequestData, *args, **kwargs): - return list(request_data.multipart_data.values())[0][0] == "custom_filename" + return next(iter(request_data.multipart_data.values()))[0] == "custom_filename" monkeypatch.setattr(bot.request, "post", make_assertion) diff --git a/tests/_files/test_voice.py b/tests/_files/test_voice.py index 24899d4af..b29260d5c 100644 --- a/tests/_files/test_voice.py +++ b/tests/_files/test_voice.py @@ -129,7 +129,7 @@ class TestVoiceWithoutRequest(TestVoiceBase): async def test_send_voice_custom_filename(self, bot, chat_id, voice_file, monkeypatch): async def make_assertion(url, request_data: RequestData, *args, **kwargs): - return list(request_data.multipart_data.values())[0][0] == "custom_filename" + return next(iter(request_data.multipart_data.values()))[0] == "custom_filename" monkeypatch.setattr(bot.request, "post", make_assertion) diff --git a/tests/_passport/test_passport.py b/tests/_passport/test_passport.py index e980f0d5b..15cf17d68 100644 --- a/tests/_passport/test_passport.py +++ b/tests/_passport/test_passport.py @@ -418,7 +418,7 @@ class TestPassportWithoutRequest(TestPassportBase): with pytest.raises(TypeError): Bot(bot.token, private_key="Invalid key!") - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="Could not deserialize key data"): Bot(bot.token, private_key=b"Invalid key!") def test_all_types(self, passport_data, bot, all_passport_data): @@ -474,7 +474,6 @@ class TestPassportWithoutRequest(TestPassportBase): with pytest.raises(PassportDecryptionError): assert passport_data.decrypted_data - wrong_key = b"-----BEGIN RSA PRIVATE KEY-----\r\nMIIEogIBAAKCAQB4qCFltuvHakZze86TUweU7E/SB3VLGEHAe7GJlBmrou9SSWsL\r\nH7E++157X6UqWFl54LOE9MeHZnoW7rZ+DxLKhk6NwAHTxXPnvw4CZlvUPC3OFxg3\r\nhEmNen6ojSM4sl4kYUIa7F+Q5uMEYaboxoBen9mbj4zzMGsG4aY/xBOb2ewrXQyL\r\nRh//tk1Px4ago+lUPisAvQVecz7/6KU4Xj4Lpv2z20f3cHlZX6bb7HlE1vixCMOf\r\nxvfC5SkWEGZMR/ZoWQUsoDkrDSITF/S3GtLfg083TgtCKaOF3mCT27sJ1og77npP\r\n0cH/qdlbdoFtdrRj3PvBpaj/TtXRhmdGcJBxAgMBAAECggEAYSq1Sp6XHo8dkV8B\r\nK2/QSURNu8y5zvIH8aUrgqo8Shb7OH9bryekrB3vJtgNwR5JYHdu2wHttcL3S4SO\r\nftJQxbyHgmxAjHUVNGqOM6yPA0o7cR70J7FnMoKVgdO3q68pVY7ll50IET9/T0X9\r\nDrTdKFb+/eILFsXFS1NpeSzExdsKq3zM0sP/vlJHHYVTmZDGaGEvny/eLAS+KAfG\r\nrKP96DeO4C/peXEJzALZ/mG1ReBB05Qp9Dx1xEC20yreRk5MnnBA5oiHVG5ZLOl9\r\nEEHINidqN+TMNSkxv67xMfQ6utNu5IpbklKv/4wqQOJOO50HZ+qBtSurTN573dky\r\nzslbCQKBgQDHDUBYyKN/v69VLmvNVcxTgrOcrdbqAfefJXb9C3dVXhS8/oRkCRU/\r\ndzxYWNT7hmQyWUKor/izh68rZ/M+bsTnlaa7IdAgyChzTfcZL/2pxG9pq05GF1Q4\r\nBSJ896ZEe3jEhbpJXRlWYvz7455svlxR0H8FooCTddTmkU3nsQSx0wKBgQCbLSa4\r\nyZs2QVstQQerNjxAtLi0IvV8cJkuvFoNC2Q21oqQc7BYU7NJL7uwriprZr5nwkCQ\r\nOFQXi4N3uqimNxuSng31ETfjFZPp+pjb8jf7Sce7cqU66xxR+anUzVZqBG1CJShx\r\nVxN7cWN33UZvIH34gA2Ax6AXNnJG42B5Gn1GKwKBgQCZ/oh/p4nGNXfiAK3qB6yy\r\nFvX6CwuvsqHt/8AUeKBz7PtCU+38roI/vXF0MBVmGky+HwxREQLpcdl1TVCERpIT\r\nUFXThI9OLUwOGI1IcTZf9tby+1LtKvM++8n4wGdjp9qAv6ylQV9u09pAzZItMwCd\r\nUx5SL6wlaQ2y60tIKk0lfQKBgBJS+56YmA6JGzY11qz+I5FUhfcnpauDNGOTdGLT\r\n9IqRPR2fu7RCdgpva4+KkZHLOTLReoRNUojRPb4WubGfEk93AJju5pWXR7c6k3Bt\r\novS2mrJk8GQLvXVksQxjDxBH44sLDkKMEM3j7uYJqDaZNKbyoCWT7TCwikAau5qx\r\naRevAoGAAKZV705dvrpJuyoHFZ66luANlrAwG/vNf6Q4mBEXB7guqMkokCsSkjqR\r\nhsD79E6q06zA0QzkLCavbCn5kMmDS/AbA80+B7El92iIN6d3jRdiNZiewkhlWhEG\r\nm4N0gQRfIu+rUjsS/4xk8UuQUT/Ossjn/hExi7ejpKdCc7N++bc=\r\n-----END RSA PRIVATE KEY-----" async with make_bot(token=bot.token, private_key=short_key) as b: passport_data = PassportData.de_json(RAW_PASSPORT_DATA, bot=b) with pytest.raises(PassportDecryptionError): diff --git a/tests/ext/test_callbackcontext.py b/tests/ext/test_callbackcontext.py index 43e1c302d..2ccb785fa 100644 --- a/tests/ext/test_callbackcontext.py +++ b/tests/ext/test_callbackcontext.py @@ -228,7 +228,7 @@ class TestCallbackContext: ), ) keyboard_uuid = app.bot.callback_data_cache.persistence_data[0][0][0] - button_uuid = list(app.bot.callback_data_cache.persistence_data[0][0][2])[0] + button_uuid = next(iter(app.bot.callback_data_cache.persistence_data[0][0][2])) callback_data = keyboard_uuid + button_uuid callback_query = CallbackQuery( id="1", diff --git a/tests/ext/test_callbackdatacache.py b/tests/ext/test_callbackdatacache.py index 862820812..052474cf2 100644 --- a/tests/ext/test_callbackdatacache.py +++ b/tests/ext/test_callbackdatacache.py @@ -202,9 +202,8 @@ class TestCallbackDataCache: assert callback_query.data == "some data 1" # make sure that we stored the mapping CallbackQuery.id -> keyboard_uuid correctly assert len(callback_data_cache._keyboard_data) == 1 - assert ( - callback_data_cache._callback_queries[cq_id] - == list(callback_data_cache._keyboard_data.keys())[0] + assert callback_data_cache._callback_queries[cq_id] == next( + iter(callback_data_cache._keyboard_data.keys()) ) else: assert callback_query.data is None @@ -399,6 +398,6 @@ class TestCallbackDataCache: assert len(callback_data_cache.persistence_data[0]) == 50 assert len(callback_data_cache.persistence_data[1]) == 100 callback_data = [ - list(data[2].values())[0] for data in callback_data_cache.persistence_data[0] + next(iter(data[2].values())) for data in callback_data_cache.persistence_data[0] ] assert callback_data == [str(i) for i in range(50, 100)] diff --git a/tests/request/test_request.py b/tests/request/test_request.py index 349166ec9..9334f7b76 100644 --- a/tests/request/test_request.py +++ b/tests/request/test_request.py @@ -543,7 +543,7 @@ class TestHTTPXRequestWithoutRequest: assert code == HTTPStatus.OK async def test_do_request_params_with_data( - self, monkeypatch, httpx_request, mixed_rqs # noqa: 9811 + self, monkeypatch, httpx_request, mixed_rqs # noqa: F811 ): async def make_assertion(self, **kwargs): method_assertion = kwargs.get("method") == "method" diff --git a/tests/test_bot.py b/tests/test_bot.py index 7bc003c48..4a89037dc 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -3251,8 +3251,10 @@ class TestBotWithRequest: assert inline_keyboard[0][1] == no_replace_button assert inline_keyboard[0][0] == replace_button - keyboard = list(bot.callback_data_cache._keyboard_data)[0] - data = list(bot.callback_data_cache._keyboard_data[keyboard].button_data.values())[0] + keyboard = next(iter(bot.callback_data_cache._keyboard_data)) + data = next( + iter(bot.callback_data_cache._keyboard_data[keyboard].button_data.values()) + ) assert data == "replace_test" finally: bot.callback_data_cache.clear_callback_data() @@ -3280,8 +3282,10 @@ class TestBotWithRequest: assert inline_keyboard[0][1] == no_replace_button assert inline_keyboard[0][0] == replace_button - keyboard = list(bot.callback_data_cache._keyboard_data)[0] - data = list(bot.callback_data_cache._keyboard_data[keyboard].button_data.values())[0] + keyboard = next(iter(bot.callback_data_cache._keyboard_data)) + data = next( + iter(bot.callback_data_cache._keyboard_data[keyboard].button_data.values()) + ) assert data == "replace_test" finally: bot.callback_data_cache.clear_callback_data() @@ -3313,8 +3317,10 @@ class TestBotWithRequest: assert inline_keyboard[0][1] == no_replace_button assert inline_keyboard[0][0] == replace_button - keyboard = list(bot.callback_data_cache._keyboard_data)[0] - data = list(bot.callback_data_cache._keyboard_data[keyboard].button_data.values())[0] + keyboard = next(iter(bot.callback_data_cache._keyboard_data)) + data = next( + iter(bot.callback_data_cache._keyboard_data[keyboard].button_data.values()) + ) assert data == "replace_test" finally: bot.callback_data_cache.clear_callback_data() @@ -3333,8 +3339,10 @@ class TestBotWithRequest: ) await message.pin() - keyboard = list(bot.callback_data_cache._keyboard_data)[0] - data = list(bot.callback_data_cache._keyboard_data[keyboard].button_data.values())[0] + keyboard = next(iter(bot.callback_data_cache._keyboard_data)) + data = next( + iter(bot.callback_data_cache._keyboard_data[keyboard].button_data.values()) + ) assert data == "callback_data" chat = await bot.get_chat(channel_id)