Skip to content

Commit 0eb7c0a

Browse files
Pierre-Sassoulasseifertm
authored andcommitted
[ruff] Add checks including pyupgrade
1 parent 594f5d0 commit 0eb7c0a

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

pyproject.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,15 @@ write_to = "pytest_asyncio/_version.py"
6969
[tool.ruff]
7070
line-length = 88
7171
lint.select = [
72-
"E", # pycodestyle
73-
"F", # pyflakes
74-
"W", # pycodestyle
72+
"E", # pycodestyle
73+
"F", # pyflakes
74+
"PGH004", # pygrep-hooks - Use specific rule codes when using noqa
75+
"PIE", # flake8-pie
76+
"PYI", # flake8-pyi
77+
"RUF", # ruff
78+
"T100", # flake8-debugger
79+
"UP", # pyupgrade
80+
"W", # pycodestyle
7581
]
7682

7783
[tool.pytest.ini_options]

pytest_asyncio/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""The main point for importing pytest-asyncio items."""
22

3-
from ._version import version as __version__ # noqa
3+
from ._version import version as __version__ # noqa: F401
44
from .plugin import fixture, is_async_test
55

66
__all__ = ("fixture", "is_async_test")

pytest_asyncio/plugin.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,21 @@
88
import socket
99
import warnings
1010
from asyncio import AbstractEventLoopPolicy
11-
from textwrap import dedent
12-
from typing import (
13-
Any,
11+
from collections.abc import (
1412
AsyncIterator,
1513
Awaitable,
16-
Callable,
17-
Dict,
1814
Generator,
1915
Iterable,
2016
Iterator,
21-
List,
22-
Literal,
2317
Mapping,
24-
Optional,
2518
Sequence,
26-
Set,
27-
Type,
19+
)
20+
from textwrap import dedent
21+
from typing import (
22+
Any,
23+
Callable,
24+
Literal,
25+
Optional,
2826
TypeVar,
2927
Union,
3028
overload,
@@ -215,7 +213,7 @@ def pytest_configure(config: Config) -> None:
215213

216214

217215
@pytest.hookimpl(tryfirst=True)
218-
def pytest_report_header(config: Config) -> List[str]:
216+
def pytest_report_header(config: Config) -> list[str]:
219217
"""Add asyncio config to pytest header."""
220218
mode = _get_asyncio_mode(config)
221219
default_loop_scope = config.getini("asyncio_default_fixture_loop_scope")
@@ -224,7 +222,7 @@ def pytest_report_header(config: Config) -> List[str]:
224222

225223
def _preprocess_async_fixtures(
226224
collector: Collector,
227-
processed_fixturedefs: Set[FixtureDef],
225+
processed_fixturedefs: set[FixtureDef],
228226
) -> None:
229227
config = collector.config
230228
default_loop_scope = config.getini("asyncio_default_fixture_loop_scope")
@@ -279,10 +277,10 @@ def _synchronize_async_fixture(fixturedef: FixtureDef) -> None:
279277

280278
def _add_kwargs(
281279
func: Callable[..., Any],
282-
kwargs: Dict[str, Any],
280+
kwargs: dict[str, Any],
283281
event_loop: asyncio.AbstractEventLoop,
284282
request: FixtureRequest,
285-
) -> Dict[str, Any]:
283+
) -> dict[str, Any]:
286284
sig = inspect.signature(func)
287285
ret = kwargs.copy()
288286
if "request" in sig.parameters:
@@ -394,7 +392,7 @@ class PytestAsyncioFunction(Function):
394392
@classmethod
395393
def item_subclass_for(
396394
cls, item: Function, /
397-
) -> Union[Type["PytestAsyncioFunction"], None]:
395+
) -> Union[type["PytestAsyncioFunction"], None]:
398396
"""
399397
Returns a subclass of PytestAsyncioFunction if there is a specialized subclass
400398
for the specified function item.
@@ -522,7 +520,7 @@ def runtest(self) -> None:
522520
super().runtest()
523521

524522

525-
_HOLDER: Set[FixtureDef] = set()
523+
_HOLDER: set[FixtureDef] = set()
526524

527525

528526
# The function name needs to start with "pytest_"
@@ -531,7 +529,7 @@ def runtest(self) -> None:
531529
def pytest_pycollect_makeitem_preprocess_async_fixtures(
532530
collector: Union[pytest.Module, pytest.Class], name: str, obj: object
533531
) -> Union[
534-
pytest.Item, pytest.Collector, List[Union[pytest.Item, pytest.Collector]], None
532+
pytest.Item, pytest.Collector, list[Union[pytest.Item, pytest.Collector]], None
535533
]:
536534
"""A pytest hook to collect asyncio coroutines."""
537535
if not collector.funcnamefilter(name):
@@ -555,7 +553,7 @@ def pytest_pycollect_makeitem_convert_async_functions_to_subclass(
555553
node_or_list_of_nodes: Union[
556554
pytest.Item,
557555
pytest.Collector,
558-
List[Union[pytest.Item, pytest.Collector]],
556+
list[Union[pytest.Item, pytest.Collector]],
559557
None,
560558
] = hook_result.get_result()
561559
except BaseException as e:
@@ -585,7 +583,7 @@ def pytest_pycollect_makeitem_convert_async_functions_to_subclass(
585583

586584

587585
_event_loop_fixture_id = StashKey[str]()
588-
_fixture_scope_by_collector_type: Mapping[Type[pytest.Collector], _ScopeName] = {
586+
_fixture_scope_by_collector_type: Mapping[type[pytest.Collector], _ScopeName] = {
589587
Class: "class",
590588
# Package is a subclass of module and the dict is used in isinstance checks
591589
# Therefore, the order matters and Package needs to appear before Module
@@ -596,7 +594,7 @@ def pytest_pycollect_makeitem_convert_async_functions_to_subclass(
596594

597595
# A stack used to push package-scoped loops during collection of a package
598596
# and pop those loops during collection of a Module
599-
__package_loop_stack: List[Union[FixtureFunctionMarker, FixtureFunction]] = []
597+
__package_loop_stack: list[Union[FixtureFunctionMarker, FixtureFunction]] = []
600598

601599

602600
@pytest.hookimpl

0 commit comments

Comments
 (0)