Skip to content

Commit 7c92e16

Browse files
authored
fix: taskiq admin middleware doesn't work with python <3.11 (#529)
1 parent 9339f9d commit 7c92e16

23 files changed

+125
-113
lines changed

poetry.lock

Lines changed: 27 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pydantic = ">=1.0,<=3.0"
3434
importlib-metadata = "*"
3535
pycron = "^3.0.0"
3636
taskiq_dependencies = ">=1.3.1,<2"
37-
anyio = ">=3"
37+
anyio = ">=4"
3838
packaging = ">=19"
3939
# For prometheus metrics
4040
prometheus_client = { version = "^0", optional = true }
@@ -104,6 +104,7 @@ multi_line_output = 3
104104

105105
[tool.pytest.ini_options]
106106
log_level = 'INFO'
107+
anyio_mode = "auto"
107108

108109
[tool.coverage.run]
109110
omit = [
@@ -122,6 +123,7 @@ requires = ["poetry-core>=1.0.0"]
122123
build-backend = "poetry.core.masonry.api"
123124

124125
[tool.ruff]
126+
target-version="py39"
125127
# List of enabled rulsets.
126128
# See https://docs.astral.sh/ruff/rules/ for more information.
127129
lint.select = [
@@ -150,6 +152,7 @@ lint.select = [
150152
"ERA", # Checks for commented out code
151153
"PL", # PyLint checks
152154
"RUF", # Specific to Ruff checks
155+
"FA102", # Future annotations
153156
]
154157
lint.ignore = [
155158
"D105", # Missing docstring in magic method
@@ -174,6 +177,7 @@ line-length = 88
174177
"SLF001", # Private member accessed
175178
"S311", # Standard pseudo-random generators are not suitable for security/cryptographic purposes
176179
"D101", # Missing docstring in public class
180+
"D102", # Missing docstring in public method
177181
]
178182

179183
[tool.ruff.lint.pydocstyle]

taskiq/middlewares/prometheus_middleware.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(
4444
logger.debug("Initializing metrics")
4545

4646
try:
47-
from prometheus_client import Counter, Histogram
47+
from prometheus_client import Counter, Histogram # noqa: PLC0415
4848
except ImportError as exc:
4949
raise ImportError(
5050
"Cannot initialize metrics. Please install 'taskiq[metrics]'.",
@@ -85,7 +85,7 @@ def startup(self) -> None:
8585
This function starts prometheus server.
8686
It starts it only in case if it's a worker process.
8787
"""
88-
from prometheus_client import start_http_server
88+
from prometheus_client import start_http_server # noqa: PLC0415
8989

9090
if self.broker.is_worker_process:
9191
try:

taskiq/middlewares/taskiq_admin_middleware.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
2-
from datetime import UTC, datetime
2+
from datetime import datetime, timezone
33
from logging import getLogger
4-
from typing import Any
4+
from typing import Any, Optional
55
from urllib.parse import urljoin
66

77
import aiohttp
@@ -36,7 +36,7 @@ def __init__(
3636
url: str,
3737
api_token: str,
3838
timeout: int = 5,
39-
taskiq_broker_name: str | None = None,
39+
taskiq_broker_name: Optional[str] = None,
4040
) -> None:
4141
super().__init__()
4242
self.url = url
@@ -48,7 +48,7 @@ def __init__(
4848

4949
@staticmethod
5050
def _now_iso() -> str:
51-
return datetime.now(UTC).replace(tzinfo=None).isoformat()
51+
return datetime.now(timezone.utc).replace(tzinfo=None).isoformat()
5252

5353
def _get_client(self) -> aiohttp.ClientSession:
5454
"""Create and cache session."""

tests/api/test_receiver_task.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from tests.utils import AsyncQueueBroker
88

99

10-
@pytest.mark.anyio
1110
async def test_successful() -> None:
1211
broker = AsyncQueueBroker()
1312
kicked = 0
@@ -28,7 +27,6 @@ def test_func() -> None:
2827
assert kicked == desired_kicked
2928

3029

31-
@pytest.mark.anyio
3230
async def test_cancelation() -> None:
3331
broker = AsyncQueueBroker()
3432
kicked = 0

tests/api/test_scheduler.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
import contextlib
33
from datetime import datetime, timedelta, timezone
44

5-
import pytest
6-
75
from taskiq import TaskiqScheduler
86
from taskiq.api import run_scheduler_task
97
from taskiq.schedule_sources import LabelScheduleSource
108
from tests.utils import AsyncQueueBroker
119

1210

13-
@pytest.mark.anyio
1411
async def test_successful() -> None:
1512
broker = AsyncQueueBroker()
1613
scheduler = TaskiqScheduler(broker, sources=[LabelScheduleSource(broker)])
@@ -26,7 +23,6 @@ def _() -> None:
2623
scheduler_task.cancel()
2724

2825

29-
@pytest.mark.anyio
3026
async def test_cancelation() -> None:
3127
broker = AsyncQueueBroker()
3228
scheduler = TaskiqScheduler(broker, sources=[LabelScheduleSource(broker)])

tests/brokers/test_inmemory.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from taskiq.state import TaskiqState
99

1010

11-
@pytest.mark.anyio
1211
async def test_inmemory_success() -> None:
1312
broker = InMemoryBroker()
1413
test_val = uuid.uuid4().hex
@@ -23,7 +22,6 @@ async def task() -> str:
2322
assert not broker._running_tasks
2423

2524

26-
@pytest.mark.anyio
2725
async def test_cannot_listen() -> None:
2826
broker = InMemoryBroker()
2927

@@ -32,7 +30,6 @@ async def test_cannot_listen() -> None:
3230
pass
3331

3432

35-
@pytest.mark.anyio
3633
async def test_startup() -> None:
3734
broker = InMemoryBroker()
3835
test_value = uuid.uuid4().hex
@@ -51,7 +48,6 @@ async def _c_startup(state: TaskiqState) -> None:
5148
assert broker.state.from_client == test_value
5249

5350

54-
@pytest.mark.anyio
5551
async def test_shutdown() -> None:
5652
broker = InMemoryBroker()
5753
test_value = uuid.uuid4().hex
@@ -70,7 +66,6 @@ async def _c_startup(state: TaskiqState) -> None:
7066
assert broker.state.from_client == test_value
7167

7268

73-
@pytest.mark.anyio
7469
async def test_execution() -> None:
7570
broker = InMemoryBroker()
7671
test_value = uuid.uuid4().hex
@@ -87,7 +82,6 @@ async def test_task() -> str:
8782
assert result.return_value == test_value
8883

8984

90-
@pytest.mark.anyio
9185
async def test_inline_awaits() -> None:
9286
broker = InMemoryBroker(await_inplace=True)
9387
slept = False
@@ -104,7 +98,6 @@ async def test_task() -> None:
10498
assert not broker._running_tasks
10599

106100

107-
@pytest.mark.anyio
108101
async def test_wait_all() -> None:
109102
broker = InMemoryBroker()
110103
slept = False

tests/cli/scheduler/test_updater.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from datetime import datetime
22
from typing import List, Union
33

4-
import pytest
5-
64
from taskiq import InMemoryBroker, ScheduleSource
75
from taskiq.cli.scheduler.run import get_all_schedules
86
from taskiq.scheduler.scheduled_task import ScheduledTask
@@ -20,7 +18,6 @@ async def get_schedules(self) -> List[ScheduledTask]:
2018
return self.schedules
2119

2220

23-
@pytest.mark.anyio
2421
async def test_get_schedules_success() -> None:
2522
"""Tests that schedules are returned correctly."""
2623
schedules1 = [
@@ -62,7 +59,6 @@ async def test_get_schedules_success() -> None:
6259
]
6360

6461

65-
@pytest.mark.anyio
6662
async def test_get_schedules_error() -> None:
6763
"""Tests that if source returned an error, empty list will be returned."""
6864
source1 = DummySource(

tests/depends/test_progress_tracker.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def get_message(
5656
)
5757

5858

59-
@pytest.mark.anyio
6059
@pytest.mark.parametrize(
6160
"state,meta",
6261
[
@@ -82,7 +81,6 @@ async def test_func(tes_val: ProgressTracker[Any] = TaskiqDepends()) -> None:
8281
assert progress.state == state
8382

8483

85-
@pytest.mark.anyio
8684
async def test_progress_tracker_ctx_none() -> None:
8785
broker = InMemoryBroker()
8886

@@ -98,7 +96,6 @@ async def test_func() -> None:
9896
assert progress is None
9997

10098

101-
@pytest.mark.anyio
10299
@pytest.mark.parametrize(
103100
"state,meta",
104101
[

tests/formatters/test_json_formatter.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import json
22

3-
import pytest
4-
53
from taskiq.formatters.json_formatter import JSONFormatter
64
from taskiq.message import BrokerMessage, TaskiqMessage
75

86

9-
@pytest.mark.anyio
107
async def test_json_dumps() -> None:
118
fmt = JSONFormatter()
129
msg = TaskiqMessage(
@@ -34,7 +31,6 @@ async def test_json_dumps() -> None:
3431
assert json.loads(dumped.message) == json.loads(expected.message)
3532

3633

37-
@pytest.mark.anyio
3834
async def test_json_loads() -> None:
3935
fmt = JSONFormatter()
4036
msg = (

0 commit comments

Comments
 (0)