Bump ruff and Remove sort-all (#4075)

This commit is contained in:
Harshil 2024-01-24 14:53:36 -05:00 committed by GitHub
parent b73dc5728e
commit 2d63c57ed6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 44 additions and 43 deletions

View file

@ -77,7 +77,7 @@ repos:
- --diff - --diff
- --check - --check
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.9' rev: 'v0.1.14'
hooks: hooks:
- id: ruff - id: ruff
name: ruff name: ruff
@ -88,9 +88,3 @@ repos:
- APScheduler~=3.10.4 - APScheduler~=3.10.4
- cachetools~=5.3.2 - cachetools~=5.3.2
- aiolimiter~=1.1.0 - aiolimiter~=1.1.0
- repo: https://github.com/aio-libs/sort-all/
rev: v1.2.0
hooks:
- id: sort-all
name: sort-all
files: ^(telegram|examples|tests)/.*\.py$

View file

@ -12,9 +12,15 @@ target-version = "py38"
show-fixes = true show-fixes = true
ignore = ["PLR2004", "PLR0911", "PLR0912", "PLR0913", "PLR0915", "PERF203"] ignore = ["PLR2004", "PLR0911", "PLR0912", "PLR0913", "PLR0915", "PERF203"]
select = ["E", "F", "I", "PL", "UP", "RUF", "PTH", "C4", "B", "PIE", "SIM", "RET", "RSE", select = ["E", "F", "I", "PL", "UP", "RUF", "PTH", "C4", "B", "PIE", "SIM", "RET", "RSE",
"G", "ISC", "PT", "ASYNC", "TCH", "SLOT", "PERF", "PYI", "FLY", "AIR"] "G", "ISC", "PT", "ASYNC", "TCH", "SLOT", "PERF", "PYI", "FLY", "AIR", "RUF022", "Q",
"INP",]
# Add "FURB" after it's out of preview # Add "FURB" after it's out of preview
[tool.ruff.lint]
preview = true
explicit-preview-rules = true
[tool.ruff.per-file-ignores] [tool.ruff.per-file-ignores]
"tests/*.py" = ["B018"] "tests/*.py" = ["B018"]
"tests/**.py" = ["RUF012"] "tests/**.py" = ["RUF012"]

View file

@ -64,6 +64,7 @@ disallow_untyped_defs = True
disallow_incomplete_defs = True disallow_incomplete_defs = True
disallow_untyped_decorators = True disallow_untyped_decorators = True
show_error_codes = True show_error_codes = True
python_version = 3.8
# For some files, it's easier to just disable strict-optional all together instead of # For some files, it's easier to just disable strict-optional all together instead of
# cluttering the code with `# type: ignore`s or stuff like # cluttering the code with `# type: ignore`s or stuff like

View file

@ -75,8 +75,8 @@ class InputLocationMessageContent(InputMessageContent):
""" """
__slots__ = ('longitude', 'horizontal_accuracy', 'proximity_alert_radius', 'live_period', __slots__ = ("longitude", "horizontal_accuracy", "proximity_alert_radius", "live_period",
'latitude', 'heading') "latitude", "heading")
# fmt: on # fmt: on
def __init__( def __init__(

View file

@ -60,7 +60,7 @@ class StringEnum(str, _enum.Enum):
# Apply the __repr__ modification and __str__ fix to IntEnum # Apply the __repr__ modification and __str__ fix to IntEnum
class IntEnum(_enum.IntEnum): class IntEnum(_enum.IntEnum): # pylint: disable=invalid-slots
"""Helper class for int enums where ``str(member)`` prints the value, but ``repr(member)`` """Helper class for int enums where ``str(member)`` prints the value, but ``repr(member)``
gives ``EnumName.MEMBER_NAME``. gives ``EnumName.MEMBER_NAME``.
""" """

View file

@ -29,11 +29,12 @@ those classes.
* Most of the constants in this module are grouped into enums. * Most of the constants in this module are grouped into enums.
""" """
# TODO: Remove this when https://github.com/PyCQA/pylint/issues/6887 is resolved. # TODO: Remove this when https://github.com/PyCQA/pylint/issues/6887 is resolved.
# pylint: disable=invalid-enum-extension # pylint: disable=invalid-enum-extension,invalid-slots
__all__ = [ __all__ = [
"BOT_API_VERSION", "BOT_API_VERSION",
"BOT_API_VERSION_INFO", "BOT_API_VERSION_INFO",
"SUPPORTED_WEBHOOK_PORTS",
"BotCommandLimit", "BotCommandLimit",
"BotCommandScopeType", "BotCommandScopeType",
"BotDescriptionLimit", "BotDescriptionLimit",
@ -75,7 +76,6 @@ __all__ = [
"PollType", "PollType",
"PollingLimit", "PollingLimit",
"ReplyLimit", "ReplyLimit",
"SUPPORTED_WEBHOOK_PORTS",
"StickerFormat", "StickerFormat",
"StickerLimit", "StickerLimit",
"StickerSetLimit", "StickerSetLimit",

View file

@ -81,7 +81,7 @@ class TrackingDict(UserDict, Generic[_KT, _VT]):
:attr:`DELETED`. :attr:`DELETED`.
""" """
keys = self.pop_accessed_keys() keys = self.pop_accessed_keys()
return [(key, self[key] if key in self else self.DELETED) for key in keys] return [(key, self.get(key, self.DELETED)) for key in keys]
def mark_as_accessed(self, key: _KT) -> None: def mark_as_accessed(self, key: _KT) -> None:
"""Use this method have the key returned again in the next call to """Use this method have the key returned again in the next call to

View file

@ -41,11 +41,34 @@ __all__ = (
"ANIMATION", "ANIMATION",
"ATTACHMENT", "ATTACHMENT",
"AUDIO", "AUDIO",
"BaseFilter",
"CAPTION", "CAPTION",
"CHAT", "CHAT",
"COMMAND", "COMMAND",
"CONTACT", "CONTACT",
"FORWARDED",
"GAME",
"HAS_MEDIA_SPOILER",
"HAS_PROTECTED_CONTENT",
"INVOICE",
"IS_AUTOMATIC_FORWARD",
"IS_TOPIC_MESSAGE",
"LOCATION",
"PASSPORT_DATA",
"PHOTO",
"POLL",
"PREMIUM_USER",
"REPLY",
"STORY",
"SUCCESSFUL_PAYMENT",
"TEXT",
"USER",
"USER_ATTACHMENT",
"VENUE",
"VIA_BOT",
"VIDEO",
"VIDEO_NOTE",
"VOICE",
"BaseFilter",
"Caption", "Caption",
"CaptionEntity", "CaptionEntity",
"CaptionRegex", "CaptionRegex",
@ -55,42 +78,19 @@ __all__ = (
"Dice", "Dice",
"Document", "Document",
"Entity", "Entity",
"FORWARDED",
"ForwardedFrom", "ForwardedFrom",
"GAME",
"HAS_MEDIA_SPOILER",
"HAS_PROTECTED_CONTENT",
"INVOICE",
"IS_AUTOMATIC_FORWARD",
"IS_TOPIC_MESSAGE",
"LOCATION",
"Language", "Language",
"Mention", "Mention",
"MessageFilter", "MessageFilter",
"PASSPORT_DATA",
"PHOTO",
"POLL",
"PREMIUM_USER",
"REPLY",
"Regex", "Regex",
"STORY",
"SUCCESSFUL_PAYMENT",
"SenderChat", "SenderChat",
"StatusUpdate", "StatusUpdate",
"Sticker", "Sticker",
"SuccessfulPayment", "SuccessfulPayment",
"TEXT",
"Text", "Text",
"USER",
"USER_ATTACHMENT",
"UpdateFilter", "UpdateFilter",
"UpdateType", "UpdateType",
"User", "User",
"VENUE",
"VIA_BOT",
"VIDEO",
"VIDEO_NOTE",
"VOICE",
"ViaBot", "ViaBot",
) )
import mimetypes import mimetypes

View file

@ -339,7 +339,7 @@ async def check_defaults_handling(
# Check InputMedia (parse_mode can have a default) # Check InputMedia (parse_mode can have a default)
def check_input_media(m: Dict): def check_input_media(m: Dict):
parse_mode = m.get("parse_mode", None) parse_mode = m.get("parse_mode")
if df_value is DEFAULT_NONE: if df_value is DEFAULT_NONE:
if parse_mode is not None: if parse_mode is not None:
pytest.fail("InputMedia has non-None parse_mode") pytest.fail("InputMedia has non-None parse_mode")

View file

@ -160,7 +160,7 @@ async def default_bot(request, bot_info):
defaults = Defaults(**param) defaults = Defaults(**param)
# If the bot is already created, return it. Else make a new one. # If the bot is already created, return it. Else make a new one.
default_bot = _default_bots.get(defaults, None) default_bot = _default_bots.get(defaults)
if default_bot is None: if default_bot is None:
default_bot = make_bot(bot_info, defaults=defaults) default_bot = make_bot(bot_info, defaults=defaults)
await default_bot.initialize() await default_bot.initialize()

View file

@ -159,8 +159,8 @@ class TestCallbackDataCache:
out2 = cdc.process_keyboard(reply_markup) out2 = cdc.process_keyboard(reply_markup)
assert len(cdc.persistence_data[0]) == 1 assert len(cdc.persistence_data[0]) == 1
keyboard_1, button_1 = cdc.extract_uuids(out1.inline_keyboard[0][1].callback_data) keyboard_1, _ = cdc.extract_uuids(out1.inline_keyboard[0][1].callback_data)
keyboard_2, button_2 = cdc.extract_uuids(out2.inline_keyboard[0][2].callback_data) keyboard_2, _ = cdc.extract_uuids(out2.inline_keyboard[0][2].callback_data)
assert cdc.persistence_data[0][0][0] != keyboard_1 assert cdc.persistence_data[0][0][0] != keyboard_1
assert cdc.persistence_data[0][0][0] == keyboard_2 assert cdc.persistence_data[0][0][0] == keyboard_2

View file

@ -460,7 +460,7 @@ class TestTelegramObject:
"and can therefore not be frozen correctly" "and can therefore not be frozen correctly"
) )
source_lines, first_line = inspect.getsourcelines(cls.__init__) source_lines, _ = inspect.getsourcelines(cls.__init__)
# We use regex matching since a simple "if self._freeze() in source_lines[-1]" would also # We use regex matching since a simple "if self._freeze() in source_lines[-1]" would also
# allo commented lines. # allo commented lines.