Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
Bibo-Joshi committed Feb 5, 2024
2 parents bedb2ce + c23eb8e commit bedef17
Show file tree
Hide file tree
Showing 122 changed files with 649 additions and 658 deletions.
32 changes: 13 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@ ci:
autoupdate_schedule: monthly

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.2.0'
hooks:
- id: ruff
name: ruff
files: ^(telegram|examples|tests)/.*\.py$
additional_dependencies:
- httpx~=0.26.0
- tornado~=6.4
- APScheduler~=3.10.4
- cachetools~=5.3.2
- aiolimiter~=1.1.0
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.1
rev: 24.1.1
hooks:
- id: black
args:
Expand All @@ -21,12 +33,6 @@ repos:
hooks:
- id: pylint
files: ^(telegram|examples)/.*\.py$
args:
- --rcfile=setup.cfg
# run pylint across multiple cpu cores to speed it up-
# https://pylint.pycqa.org/en/latest/user_guide/run.html?#parallel-execution to know more
- --jobs=0

additional_dependencies:
- httpx~=0.26.0
- tornado~=6.4
Expand Down Expand Up @@ -76,15 +82,3 @@ repos:
args:
- --diff
- --check
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.14'
hooks:
- id: ruff
name: ruff
files: ^(telegram|examples|tests)/.*\.py$
additional_dependencies:
- httpx~=0.26.0
- tornado~=6.4
- APScheduler~=3.10.4
- cachetools~=5.3.2
- aiolimiter~=1.1.0
1 change: 0 additions & 1 deletion docs/requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
sphinx==7.2.6
sphinx-pypi-upload
furo==2024.1.29
git+https://github.com/harshil21/furo-sphinx-search@v0.2.0.1
sphinx-paramlinks==0.6.0
Expand Down
115 changes: 107 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,125 @@
# BLACK:
[tool.black]
line-length = 99
target-version = ['py38', 'py39', 'py310', 'py311']

# ISORT:
[tool.isort] # black config
profile = "black"
line_length = 99

# RUFF:
[tool.ruff]
line-length = 99
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", "RUF022", "Q",
"INP",]

# Add "FURB" after it's out of preview

[tool.ruff.lint]
preview = true
explicit-preview-rules = 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", "RUF022",
"RUF023", "Q", "INP",]
# Add "FURB" after it's out of preview

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"tests/*.py" = ["B018"]
"tests/**.py" = ["RUF012"]
"tests/**.py" = ["RUF012", "ASYNC101"]

# PYLINT:
[tool.pylint."messages control"]
enable = ["useless-suppression"]
disable = ["duplicate-code", "too-many-arguments", "too-many-public-methods",
"too-few-public-methods", "broad-exception-caught", "too-many-instance-attributes",
"fixme", "missing-function-docstring", "missing-class-docstring", "too-many-locals",
"too-many-lines", "too-many-branches", "too-many-statements", "cyclic-import"
]

[tool.pylint.main]
# run pylint across multiple cpu cores to speed it up-
# https://pylint.pycqa.org/en/latest/user_guide/run.html?#parallel-execution to know more
jobs = 0

[tool.pylint.classes]
exclude-protected = ["_unfrozen"]

# PYTEST:
[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "--no-success-flaky-report -rsxX"
filterwarnings = [
"error",
"ignore::DeprecationWarning",
'ignore:Tasks created via `Application\.create_task` while the application is not running',
"ignore::ResourceWarning",
# TODO: Write so good code that we don't need to ignore ResourceWarnings anymore
# Unfortunately due to https://github.com/pytest-dev/pytest/issues/8343 we can't have this here
# and instead do a trick directly in tests/conftest.py
# ignore::telegram.utils.deprecate.TelegramDeprecationWarning
]
markers = [
"dev", # If you want to test a specific test, use this
"no_req",
"req",
]
asyncio_mode = "auto"

# MYPY:
[tool.mypy]
warn_unused_ignores = true
warn_unused_configs = true
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
# `if self.text is None: raise RuntimeError()`
[[tool.mypy.overrides]]
module = [
"telegram._callbackquery",
"telegram._file",
"telegram._message",
"telegram._files.file"
]
strict_optional = false

# type hinting for asyncio in webhookhandler is a bit tricky because it depends on the OS
[[tool.mypy.overrides]]
module = "telegram.ext._utils.webhookhandler"
warn_unused_ignores = false

# The libs listed below are only used for the `customwebhookbot_*.py` examples
# let's just ignore type checking for them for now
[[tool.mypy.overrides]]
module = [
"flask.*",
"quart.*",
"starlette.*",
"uvicorn.*",
"asgiref.*",
"django.*",
"apscheduler.*", # not part of `customwebhookbot_*.py` examples
]
ignore_missing_imports = true

# COVERAGE:
[tool.coverage.run]
branch = true
source = ["telegram"]
parallel = true
concurrency = ["thread", "multiprocessing"]
omit = [
"tests/",
"telegram/__main__.py"
]

[tool.coverage.report]
exclude_also = [
"@overload",
"@abstractmethod",
"if TYPE_CHECKING:"
]
89 changes: 1 addition & 88 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,95 +1,8 @@
[metadata]
license_files = LICENSE, LICENSE.dual, LICENSE.lesser

[build_sphinx]
source-dir = docs/source
build-dir = docs/build
all_files = 1

[upload_sphinx]
upload-dir = docs/build/html

[flake8]
max-line-length = 99
ignore = W503, W605
extend-ignore = E203
extend-ignore = E203, E704
exclude = setup.py, setup-raw.py docs/source/conf.py

[pylint.message-control]
disable = duplicate-code,too-many-arguments,too-many-public-methods,too-few-public-methods,
broad-except,too-many-instance-attributes,fixme,missing-function-docstring,
missing-class-docstring,too-many-locals,too-many-lines,too-many-branches,
too-many-statements, cyclic-import
enable=useless-suppression ; Warns about unused pylint ignores
exclude-protected=_unfrozen

[tool:pytest]
testpaths = tests
addopts = --no-success-flaky-report -rsxX
filterwarnings =
error
ignore::DeprecationWarning
ignore:Tasks created via `Application\.create_task` while the application is not running
ignore::ResourceWarning
; TODO: Write so good code that we don't need to ignore ResourceWarnings anymore

; Unfortunately due to https://github.com/pytest-dev/pytest/issues/8343 we can't have this here
; and instead do a trick directly in tests/conftest.py
; ignore::telegram.utils.deprecate.TelegramDeprecationWarning
markers =
dev: If you want to test a specific test, use this
no_req
req
asyncio_mode = auto

[coverage:run]
branch = True
source = telegram
parallel = True
concurrency = thread, multiprocessing
omit =
tests/
telegram/__main__.py

[coverage:report]
exclude_lines =
pragma: no cover
@overload
if TYPE_CHECKING:

[mypy]
warn_unused_ignores = True
warn_unused_configs = True
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
# `if self.text is None: raise RuntimeError()`
[mypy-telegram._callbackquery,telegram._file,telegram._message,telegram._files.file]
strict_optional = False

# type hinting for asyncio in webhookhandler is a bit tricky because it depends on the OS
[mypy-telegram.ext._utils.webhookhandler]
warn_unused_ignores = False

[mypy-apscheduler.*]
ignore_missing_imports = True

# The libs listed below are only used for the `customwebhookbot_*.py` examples
# let's just ignore type checking for them for now
[mypy-uvicorn.*]
ignore_missing_imports = True
[mypy-starlette.*]
ignore_missing_imports = True
[mypy-asgiref.*]
ignore_missing_imports = True
[mypy-flask.*]
ignore_missing_imports = True
[mypy-quart.*]
ignore_missing_imports = True
[mypy-django.*]
ignore_missing_imports = True
22 changes: 12 additions & 10 deletions telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,14 @@ class Bot(TelegramObject, AsyncContextManager["Bot"]):
_LOGGER = get_logger(__name__)

__slots__ = (
"_token",
"_base_url",
"_base_file_url",
"_private_key",
"_base_url",
"_bot_user",
"_request",
"_initialized",
"_local_mode",
"_private_key",
"_request",
"_token",
)

def __init__(
Expand Down Expand Up @@ -8637,12 +8637,14 @@ async def set_message_reaction(
allowed_reactions: Set[str] = set(ReactionEmoji)
parsed_reaction = (
[
entry
if isinstance(entry, ReactionType)
else (
ReactionTypeEmoji(emoji=entry)
if entry in allowed_reactions
else ReactionTypeCustomEmoji(custom_emoji_id=entry)
(
entry
if isinstance(entry, ReactionType)
else (
ReactionTypeEmoji(emoji=entry)
if entry in allowed_reactions
else ReactionTypeCustomEmoji(custom_emoji_id=entry)
)
)
for entry in (
[reaction] if isinstance(reaction, (ReactionType, str)) else reaction
Expand Down
2 changes: 1 addition & 1 deletion telegram/_botcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class BotCommand(TelegramObject):
"""

__slots__ = ("description", "command")
__slots__ = ("command", "description")

def __init__(self, command: str, description: str, *, api_kwargs: Optional[JSONDict] = None):
super().__init__(api_kwargs=api_kwargs)
Expand Down
14 changes: 7 additions & 7 deletions telegram/_callbackquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ class CallbackQuery(TelegramObject):
"""

__slots__ = (
"game_short_name",
"message",
"chat_instance",
"id",
"data",
"from_user",
"game_short_name",
"id",
"inline_message_id",
"data",
"message",
)

def __init__(
Expand Down Expand Up @@ -860,9 +860,9 @@ async def copy_message(
reply_parameters=reply_parameters,
)

MAX_ANSWER_TEXT_LENGTH: Final[
int
] = constants.CallbackQueryLimit.ANSWER_CALLBACK_QUERY_TEXT_LENGTH
MAX_ANSWER_TEXT_LENGTH: Final[int] = (
constants.CallbackQueryLimit.ANSWER_CALLBACK_QUERY_TEXT_LENGTH
)
"""
:const:`telegram.constants.CallbackQueryLimit.ANSWER_CALLBACK_QUERY_TEXT_LENGTH`
Expand Down
6 changes: 3 additions & 3 deletions telegram/_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ def __init__(
self.location: Optional[ChatLocation] = location
self.join_to_send_messages: Optional[bool] = join_to_send_messages
self.join_by_request: Optional[bool] = join_by_request
self.has_restricted_voice_and_video_messages: Optional[
bool
] = has_restricted_voice_and_video_messages
self.has_restricted_voice_and_video_messages: Optional[bool] = (
has_restricted_voice_and_video_messages
)
self.is_forum: Optional[bool] = is_forum
self.active_usernames: Tuple[str, ...] = parse_sequence_arg(active_usernames)
self.emoji_status_custom_emoji_id: Optional[str] = emoji_status_custom_emoji_id
Expand Down
Loading

0 comments on commit bedef17

Please sign in to comment.