mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-23 07:38:58 +01:00
Bump ruff
and Add New Rules (#4329)
This commit is contained in:
parent
51ef571a07
commit
cfc75bb08b
7 changed files with 27 additions and 25 deletions
|
@ -7,7 +7,7 @@ ci:
|
|||
|
||||
repos:
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: 'v0.4.3'
|
||||
rev: 'v0.5.0'
|
||||
hooks:
|
||||
- id: ruff
|
||||
name: ruff
|
||||
|
|
|
@ -47,9 +47,9 @@ async def msg(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
|||
# Files will be downloaded to current directory
|
||||
for data in passport_data.decrypted_data: # This is where the data gets decrypted
|
||||
if data.type == "phone_number":
|
||||
print("Phone: ", data.phone_number)
|
||||
logger.info("Phone: %s", data.phone_number)
|
||||
elif data.type == "email":
|
||||
print("Email: ", data.email)
|
||||
logger.info("Email: %s", data.email)
|
||||
if data.type in (
|
||||
"personal_details",
|
||||
"passport",
|
||||
|
@ -58,7 +58,7 @@ async def msg(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
|||
"internal_passport",
|
||||
"address",
|
||||
):
|
||||
print(data.type, data.data)
|
||||
logger.info(data.type, data.data)
|
||||
if data.type in (
|
||||
"utility_bill",
|
||||
"bank_statement",
|
||||
|
@ -66,28 +66,28 @@ async def msg(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
|||
"passport_registration",
|
||||
"temporary_registration",
|
||||
):
|
||||
print(data.type, len(data.files), "files")
|
||||
logger.info(data.type, len(data.files), "files")
|
||||
for file in data.files:
|
||||
actual_file = await file.get_file()
|
||||
print(actual_file)
|
||||
logger.info(actual_file)
|
||||
await actual_file.download_to_drive()
|
||||
if (
|
||||
data.type in ("passport", "driver_license", "identity_card", "internal_passport")
|
||||
and data.front_side
|
||||
):
|
||||
front_file = await data.front_side.get_file()
|
||||
print(data.type, front_file)
|
||||
logger.info(data.type, front_file)
|
||||
await front_file.download_to_drive()
|
||||
if data.type in ("driver_license" and "identity_card") and data.reverse_side:
|
||||
reverse_file = await data.reverse_side.get_file()
|
||||
print(data.type, reverse_file)
|
||||
logger.info(data.type, reverse_file)
|
||||
await reverse_file.download_to_drive()
|
||||
if (
|
||||
data.type in ("passport", "driver_license", "identity_card", "internal_passport")
|
||||
and data.selfie
|
||||
):
|
||||
selfie_file = await data.selfie.get_file()
|
||||
print(data.type, selfie_file)
|
||||
logger.info(data.type, selfie_file)
|
||||
await selfie_file.download_to_drive()
|
||||
if data.translation and data.type in (
|
||||
"passport",
|
||||
|
@ -100,10 +100,10 @@ async def msg(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
|||
"passport_registration",
|
||||
"temporary_registration",
|
||||
):
|
||||
print(data.type, len(data.translation), "translation")
|
||||
logger.info(data.type, len(data.translation), "translation")
|
||||
for file in data.translation:
|
||||
actual_file = await file.get_file()
|
||||
print(actual_file)
|
||||
logger.info(actual_file)
|
||||
await actual_file.download_to_drive()
|
||||
|
||||
|
||||
|
|
|
@ -124,17 +124,16 @@ show-fixes = true
|
|||
|
||||
[tool.ruff.lint]
|
||||
preview = true
|
||||
explicit-preview-rules = true
|
||||
explicit-preview-rules = true # TODO: Drop this when RUF022 and RUF023 are out of preview
|
||||
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", "RUF022",
|
||||
"RUF023", "Q", "INP", "W", "YTT", "DTZ", "ARG"]
|
||||
# Add "FURB" after it's out of preview
|
||||
"RUF023", "Q", "INP", "W", "YTT", "DTZ", "ARG", "T20", "FURB"]
|
||||
# Add "A (flake8-builtins)" after we drop pylint
|
||||
|
||||
[tool.ruff.lint.per-file-ignores]
|
||||
"tests/*.py" = ["B018"]
|
||||
"tests/**.py" = ["RUF012", "ASYNC101", "DTZ", "ARG"]
|
||||
"tests/**.py" = ["RUF012", "ASYNC230", "DTZ", "ARG", "T201"]
|
||||
"docs/**.py" = ["INP001", "ARG"]
|
||||
"examples/**.py" = ["ARG"]
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
# pylint: disable=missing-module-docstring
|
||||
# ruff: noqa: T201
|
||||
import subprocess
|
||||
import sys
|
||||
from typing import Optional
|
||||
|
|
|
@ -106,7 +106,9 @@ class JobQueue(Generic[CCT]):
|
|||
|
||||
self._application: Optional[weakref.ReferenceType[Application]] = None
|
||||
self._executor = AsyncIOExecutor()
|
||||
self.scheduler: "AsyncIOScheduler" = AsyncIOScheduler(**self.scheduler_configuration)
|
||||
self.scheduler: "AsyncIOScheduler" = AsyncIOScheduler( # noqa: UP037
|
||||
**self.scheduler_configuration
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""Give a string representation of the JobQueue in the form ``JobQueue[application=...]``.
|
||||
|
|
|
@ -605,9 +605,9 @@ class TestHTTPXRequestWithoutRequest:
|
|||
read_timeout=default_timeouts.read,
|
||||
write_timeout=default_timeouts.write,
|
||||
pool_timeout=default_timeouts.pool,
|
||||
) as httpx_request:
|
||||
) as httpx_request_ctx:
|
||||
monkeypatch.setattr(httpx.AsyncClient, "request", make_assertion)
|
||||
await httpx_request.do_request(
|
||||
await httpx_request_ctx.do_request(
|
||||
method="GET",
|
||||
url="URL",
|
||||
connect_timeout=manual_timeouts.connect,
|
||||
|
|
|
@ -559,11 +559,11 @@ class TestBotWithoutRequest:
|
|||
copied_result = copy.copy(result)
|
||||
|
||||
ext_bot = bot
|
||||
for bot in (ext_bot, raw_bot):
|
||||
for bot_type in (ext_bot, raw_bot):
|
||||
# We need to test 1) below both the bot and raw_bot and setting this up with
|
||||
# pytest.parametrize appears to be difficult ...
|
||||
monkeypatch.setattr(bot.request, "post", make_assertion)
|
||||
web_app_msg = await bot.answer_web_app_query("12345", result)
|
||||
monkeypatch.setattr(bot_type.request, "post", make_assertion)
|
||||
web_app_msg = await bot_type.answer_web_app_query("12345", result)
|
||||
assert params, "something went wrong with passing arguments to the request"
|
||||
assert isinstance(web_app_msg, SentWebAppMessage)
|
||||
assert web_app_msg.inline_message_id == "321"
|
||||
|
@ -761,11 +761,11 @@ class TestBotWithoutRequest:
|
|||
|
||||
copied_results = copy.copy(results)
|
||||
ext_bot = bot
|
||||
for bot in (ext_bot, raw_bot):
|
||||
for bot_type in (ext_bot, raw_bot):
|
||||
# We need to test 1) below both the bot and raw_bot and setting this up with
|
||||
# pytest.parametrize appears to be difficult ...
|
||||
monkeypatch.setattr(bot.request, "post", make_assertion)
|
||||
assert await bot.answer_inline_query(
|
||||
monkeypatch.setattr(bot_type.request, "post", make_assertion)
|
||||
assert await bot_type.answer_inline_query(
|
||||
1234,
|
||||
results=results,
|
||||
cache_time=300,
|
||||
|
@ -790,7 +790,7 @@ class TestBotWithoutRequest:
|
|||
copied_results[idx].input_message_content, "disable_web_page_preview", None
|
||||
)
|
||||
|
||||
monkeypatch.delattr(bot.request, "post")
|
||||
monkeypatch.delattr(bot_type.request, "post")
|
||||
|
||||
async def test_answer_inline_query_no_default_parse_mode(self, monkeypatch, bot):
|
||||
async def make_assertion(url, request_data: RequestData, *args, **kwargs):
|
||||
|
|
Loading…
Reference in a new issue