mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-06 16:15:51 +00:00
Upgrade to py12 (#1354)
* Upgrade to py12 compatible aiohttp beta version * Fix uvloop deprecation warning causing pytest not to run * Fix test due to asyncio task scheduling race condition * Fix test_state_in_unknown_class for Python 3.12+ due to PEP 678 changes * Add Python 3.12 support in GitHub Actions and project configurations * Add changelog entry --------- Co-authored-by: Alex Root Junior <jroot.junior@gmail.com>
This commit is contained in:
parent
c208bcf748
commit
c1bafea3e8
6 changed files with 35 additions and 7 deletions
1
.github/workflows/tests.yml
vendored
1
.github/workflows/tests.yml
vendored
|
|
@ -33,6 +33,7 @@ jobs:
|
||||||
- '3.9'
|
- '3.9'
|
||||||
- '3.10'
|
- '3.10'
|
||||||
- '3.11'
|
- '3.11'
|
||||||
|
- '3.12'
|
||||||
- 'pypy3.8'
|
- 'pypy3.8'
|
||||||
- 'pypy3.9'
|
- 'pypy3.9'
|
||||||
|
|
||||||
|
|
|
||||||
1
CHANGES/1354.misc.rst
Normal file
1
CHANGES/1354.misc.rst
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Introduce Python 3.12 support
|
||||||
|
|
@ -15,8 +15,10 @@ from .utils.text_decorations import markdown_decoration as md
|
||||||
|
|
||||||
with suppress(ImportError):
|
with suppress(ImportError):
|
||||||
import uvloop as _uvloop
|
import uvloop as _uvloop
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
asyncio.set_event_loop_policy(_uvloop.EventLoopPolicy())
|
||||||
|
|
||||||
_uvloop.install() # type: ignore[attr-defined,unused-ignore]
|
|
||||||
|
|
||||||
F = MagicFilter()
|
F = MagicFilter()
|
||||||
flags = FlagGenerator()
|
flags = FlagGenerator()
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ classifiers = [
|
||||||
"Programming Language :: Python :: 3.9",
|
"Programming Language :: Python :: 3.9",
|
||||||
"Programming Language :: Python :: 3.10",
|
"Programming Language :: Python :: 3.10",
|
||||||
"Programming Language :: Python :: 3.11",
|
"Programming Language :: Python :: 3.11",
|
||||||
|
"Programming Language :: Python :: 3.12",
|
||||||
"Programming Language :: Python :: Implementation :: PyPy",
|
"Programming Language :: Python :: Implementation :: PyPy",
|
||||||
"Topic :: Software Development :: Libraries :: Application Frameworks",
|
"Topic :: Software Development :: Libraries :: Application Frameworks",
|
||||||
"Topic :: Software Development :: Libraries :: Python Modules",
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||||
|
|
@ -41,7 +42,7 @@ classifiers = [
|
||||||
]
|
]
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"magic-filter>=1.0.12,<1.1",
|
"magic-filter>=1.0.12,<1.1",
|
||||||
"aiohttp~=3.8.5",
|
"aiohttp~=3.9.0",
|
||||||
"pydantic>=2.4.1,<2.6",
|
"pydantic>=2.4.1,<2.6",
|
||||||
"aiofiles~=23.2.1",
|
"aiofiles~=23.2.1",
|
||||||
"certifi>=2023.7.22",
|
"certifi>=2023.7.22",
|
||||||
|
|
@ -144,7 +145,7 @@ features = [
|
||||||
serve = "sphinx-autobuild --watch aiogram/ --watch CHANGELOG.rst --watch README.rst docs/ docs/_build/ {args}"
|
serve = "sphinx-autobuild --watch aiogram/ --watch CHANGELOG.rst --watch README.rst docs/ docs/_build/ {args}"
|
||||||
|
|
||||||
[tool.hatch.envs.dev]
|
[tool.hatch.envs.dev]
|
||||||
python = "3.11"
|
python = "3.12"
|
||||||
features = [
|
features = [
|
||||||
"dev",
|
"dev",
|
||||||
"fast",
|
"fast",
|
||||||
|
|
@ -185,7 +186,7 @@ view-cov = "google-chrome-stable reports/py{matrix:python}/coverage/index.html"
|
||||||
|
|
||||||
|
|
||||||
[[tool.hatch.envs.test.matrix]]
|
[[tool.hatch.envs.test.matrix]]
|
||||||
python = ["38", "39", "310", "311"]
|
python = ["38", "39", "310", "311", "312"]
|
||||||
|
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
line-length = 99
|
line-length = 99
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
import sys
|
||||||
|
|
||||||
from aiogram.fsm.state import State, StatesGroup, any_state
|
from aiogram.fsm.state import State, StatesGroup, any_state
|
||||||
|
|
||||||
|
PY312_OR_GREATER = sys.version_info >= (3, 12)
|
||||||
|
|
||||||
|
|
||||||
class TestState:
|
class TestState:
|
||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
|
|
@ -72,10 +75,20 @@ class TestState:
|
||||||
assert state(None, check) is result
|
assert state(None, check) is result
|
||||||
|
|
||||||
def test_state_in_unknown_class(self):
|
def test_state_in_unknown_class(self):
|
||||||
with pytest.raises(RuntimeError):
|
if PY312_OR_GREATER:
|
||||||
|
# Python 3.12+ does not wrap __set_name__ exceptions with RuntimeError anymore as part
|
||||||
|
# of PEP 678. See "Other Language Changes" in the changelogs:
|
||||||
|
# https://docs.python.org/3/whatsnew/3.12.html
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
|
||||||
class MyClass:
|
class MyClass:
|
||||||
state1 = State()
|
state1 = State()
|
||||||
|
|
||||||
|
else:
|
||||||
|
with pytest.raises(RuntimeError):
|
||||||
|
|
||||||
|
class MyClass:
|
||||||
|
state1 = State()
|
||||||
|
|
||||||
|
|
||||||
class TestStatesGroup:
|
class TestStatesGroup:
|
||||||
|
|
|
||||||
|
|
@ -181,10 +181,20 @@ class TestSimpleRequestHandler:
|
||||||
"aiogram.dispatcher.dispatcher.Dispatcher.silent_call_request",
|
"aiogram.dispatcher.dispatcher.Dispatcher.silent_call_request",
|
||||||
new_callable=AsyncMock,
|
new_callable=AsyncMock,
|
||||||
) as mocked_silent_call_request:
|
) as mocked_silent_call_request:
|
||||||
|
method_called_event = asyncio.Event()
|
||||||
|
mocked_silent_call_request.side_effect = (
|
||||||
|
lambda *args, **kwargs: method_called_event.set()
|
||||||
|
)
|
||||||
|
|
||||||
handler_event.clear()
|
handler_event.clear()
|
||||||
resp = await self.make_reqest(client=client)
|
resp = await self.make_reqest(client=client)
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
await asyncio.wait_for(handler_event.wait(), timeout=1)
|
await asyncio.wait_for(handler_event.wait(), timeout=1)
|
||||||
|
await asyncio.wait_for(method_called_event.wait(), timeout=1)
|
||||||
|
# Python 3.12 had some changes to asyncio which make it quite a bit faster. But
|
||||||
|
# probably because of that the assert_awaited call is consistently scheduled before the
|
||||||
|
# silent_call_request call - failing the test. So we wait for the method to be called
|
||||||
|
# before asserting if it has been awaited.
|
||||||
mocked_silent_call_request.assert_awaited()
|
mocked_silent_call_request.assert_awaited()
|
||||||
result = await resp.json()
|
result = await resp.json()
|
||||||
assert not result
|
assert not result
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue