Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions examples/passportbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information

This expression logs [sensitive data (private)](1) as clear text.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, first time I see this security feature doing something:D

elif data.type == "email":
print("Email: ", data.email)
logger.info("Email: %s", data.email)
if data.type in (
"personal_details",
"passport",
Expand All @@ -58,36 +58,36 @@ 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",
"rental_agreement",
"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",
Expand All @@ -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()


Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
1 change: 1 addition & 0 deletions telegram/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion telegram/ext/_jobqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def __init__(self) -> None:

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=...]``.
Expand Down
4 changes: 2 additions & 2 deletions tests/request/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,9 @@ async def make_assertion(_, **kwargs):
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,
Expand Down
14 changes: 7 additions & 7 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,11 @@ async def make_assertion(url, request_data: RequestData, *args, **kwargs):
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"
Expand Down Expand Up @@ -761,11 +761,11 @@ async def make_assertion(url, request_data: RequestData, *args, **kwargs):

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,
Expand All @@ -790,7 +790,7 @@ async def make_assertion(url, request_data: RequestData, *args, **kwargs):
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):
Expand Down