Skip to content

Commit

Permalink
Bump ruff and Remove sort-all (#4075)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshil21 committed Jan 24, 2024
1 parent b73dc57 commit 2d63c57
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 42 deletions.
8 changes: 1 addition & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ repos:
- --diff
- --check
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.9'
rev: 'v0.1.14'
hooks:
- id: ruff
name: ruff
Expand All @@ -88,9 +88,3 @@ repos:
- APScheduler~=3.10.4
- cachetools~=5.3.2
- 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$
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ 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", "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

[tool.ruff.lint]
preview = true
explicit-preview-rules = true

[tool.ruff.per-file-ignores]
"tests/*.py" = ["B018"]
"tests/**.py" = ["RUF012"]
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ disallow_untyped_defs = True
disallow_incomplete_defs = True
disallow_untyped_decorators = True
show_error_codes = True
python_version = 3.8

# 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
Expand Down
4 changes: 2 additions & 2 deletions telegram/_inline/inputlocationmessagecontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class InputLocationMessageContent(InputMessageContent):
"""

__slots__ = ('longitude', 'horizontal_accuracy', 'proximity_alert_radius', 'live_period',
'latitude', 'heading')
__slots__ = ("longitude", "horizontal_accuracy", "proximity_alert_radius", "live_period",
"latitude", "heading")
# fmt: on

def __init__(
Expand Down
2 changes: 1 addition & 1 deletion telegram/_utils/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __str__(self) -> str:


# 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)``
gives ``EnumName.MEMBER_NAME``.
"""
Expand Down
4 changes: 2 additions & 2 deletions telegram/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
* Most of the constants in this module are grouped into enums.
"""
# 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__ = [
"BOT_API_VERSION",
"BOT_API_VERSION_INFO",
"SUPPORTED_WEBHOOK_PORTS",
"BotCommandLimit",
"BotCommandScopeType",
"BotDescriptionLimit",
Expand Down Expand Up @@ -75,7 +76,6 @@
"PollType",
"PollingLimit",
"ReplyLimit",
"SUPPORTED_WEBHOOK_PORTS",
"StickerFormat",
"StickerLimit",
"StickerSetLimit",
Expand Down
2 changes: 1 addition & 1 deletion telegram/ext/_utils/trackingdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def pop_accessed_write_items(self) -> List[Tuple[_KT, _VT]]:
:attr:`DELETED`.
"""
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:
"""Use this method have the key returned again in the next call to
Expand Down
46 changes: 23 additions & 23 deletions telegram/ext/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,56 +41,56 @@
"ANIMATION",
"ATTACHMENT",
"AUDIO",
"BaseFilter",
"CAPTION",
"CHAT",
"COMMAND",
"CONTACT",
"Caption",
"CaptionEntity",
"CaptionRegex",
"Chat",
"ChatType",
"Command",
"Dice",
"Document",
"Entity",
"FORWARDED",
"ForwardedFrom",
"GAME",
"HAS_MEDIA_SPOILER",
"HAS_PROTECTED_CONTENT",
"INVOICE",
"IS_AUTOMATIC_FORWARD",
"IS_TOPIC_MESSAGE",
"LOCATION",
"Language",
"Mention",
"MessageFilter",
"PASSPORT_DATA",
"PHOTO",
"POLL",
"PREMIUM_USER",
"REPLY",
"Regex",
"STORY",
"SUCCESSFUL_PAYMENT",
"SenderChat",
"StatusUpdate",
"Sticker",
"SuccessfulPayment",
"TEXT",
"Text",
"USER",
"USER_ATTACHMENT",
"UpdateFilter",
"UpdateType",
"User",
"VENUE",
"VIA_BOT",
"VIDEO",
"VIDEO_NOTE",
"VOICE",
"BaseFilter",
"Caption",
"CaptionEntity",
"CaptionRegex",
"Chat",
"ChatType",
"Command",
"Dice",
"Document",
"Entity",
"ForwardedFrom",
"Language",
"Mention",
"MessageFilter",
"Regex",
"SenderChat",
"StatusUpdate",
"Sticker",
"SuccessfulPayment",
"Text",
"UpdateFilter",
"UpdateType",
"User",
"ViaBot",
)
import mimetypes
Expand Down
2 changes: 1 addition & 1 deletion tests/auxil/bot_method_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ async def make_assertion(

# Check InputMedia (parse_mode can have a default)
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 parse_mode is not None:
pytest.fail("InputMedia has non-None parse_mode")
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async def default_bot(request, bot_info):
defaults = Defaults(**param)

# 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:
default_bot = make_bot(bot_info, defaults=defaults)
await default_bot.initialize()
Expand Down
4 changes: 2 additions & 2 deletions tests/ext/test_callbackdatacache.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def test_process_keyboard_full(self, bot):
out2 = cdc.process_keyboard(reply_markup)
assert len(cdc.persistence_data[0]) == 1

keyboard_1, button_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_1, _ = cdc.extract_uuids(out1.inline_keyboard[0][1].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_2

Expand Down
2 changes: 1 addition & 1 deletion tests/test_telegramobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def test_subclasses_are_frozen(self, cls):
"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
# allo commented lines.
Expand Down

0 comments on commit 2d63c57

Please sign in to comment.