Skip to content

Commit b6df009

Browse files
[typing.Union -> |] Add 'from __future__ import annotations' everywhere
1 parent 7054479 commit b6df009

39 files changed

+112
-44
lines changed

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ lint.select = [
7474
"D", # pydocstyle
7575
"E", # pycodestyle
7676
"F", # pyflakes
77+
"FA100", # add future annotations
7778
"PGH004", # pygrep-hooks - Use specific rule codes when using noqa
7879
"PIE", # flake8-pie
80+
"PLE", # pylint error
7981
"PYI", # flake8-pyi
8082
"RUF", # ruff
8183
"T100", # flake8-debugger

pytest_asyncio/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""The main point for importing pytest-asyncio items."""
22

3+
from __future__ import annotations
4+
35
from ._version import version as __version__ # noqa: F401
46
from .plugin import fixture, is_async_test
57

pytest_asyncio/plugin.py

+36-44
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""pytest-asyncio implementation."""
22

3+
from __future__ import annotations
4+
35
import asyncio
46
import contextlib
57
import enum
@@ -22,7 +24,6 @@
2224
Any,
2325
Callable,
2426
Literal,
25-
Optional,
2627
TypeVar,
2728
Union,
2829
overload,
@@ -110,41 +111,41 @@ def pytest_addoption(parser: Parser, pluginmanager: PytestPluginManager) -> None
110111
def fixture(
111112
fixture_function: FixtureFunction,
112113
*,
113-
scope: "Union[_ScopeName, Callable[[str, Config], _ScopeName]]" = ...,
114-
loop_scope: Union[_ScopeName, None] = ...,
115-
params: Optional[Iterable[object]] = ...,
114+
scope: _ScopeName | Callable[[str, Config], _ScopeName] = ...,
115+
loop_scope: _ScopeName | None = ...,
116+
params: Iterable[object] | None = ...,
116117
autouse: bool = ...,
117-
ids: Union[
118-
Iterable[Union[str, float, int, bool, None]],
119-
Callable[[Any], Optional[object]],
120-
None,
121-
] = ...,
122-
name: Optional[str] = ...,
118+
ids: (
119+
Iterable[str | float | int | bool | None]
120+
| Callable[[Any], object | None]
121+
| None
122+
) = ...,
123+
name: str | None = ...,
123124
) -> FixtureFunction: ...
124125

125126

126127
@overload
127128
def fixture(
128129
fixture_function: None = ...,
129130
*,
130-
scope: "Union[_ScopeName, Callable[[str, Config], _ScopeName]]" = ...,
131-
loop_scope: Union[_ScopeName, None] = ...,
132-
params: Optional[Iterable[object]] = ...,
131+
scope: _ScopeName | Callable[[str, Config], _ScopeName] = ...,
132+
loop_scope: _ScopeName | None = ...,
133+
params: Iterable[object] | None = ...,
133134
autouse: bool = ...,
134-
ids: Union[
135-
Iterable[Union[str, float, int, bool, None]],
136-
Callable[[Any], Optional[object]],
137-
None,
138-
] = ...,
139-
name: Optional[str] = None,
135+
ids: (
136+
Iterable[str | float | int | bool | None]
137+
| Callable[[Any], object | None]
138+
| None
139+
) = ...,
140+
name: str | None = None,
140141
) -> FixtureFunctionMarker: ...
141142

142143

143144
def fixture(
144-
fixture_function: Optional[FixtureFunction] = None,
145-
loop_scope: Union[_ScopeName, None] = None,
145+
fixture_function: FixtureFunction | None = None,
146+
loop_scope: _ScopeName | None = None,
146147
**kwargs: Any,
147-
) -> Union[FixtureFunction, FixtureFunctionMarker]:
148+
) -> FixtureFunction | FixtureFunctionMarker:
148149
if fixture_function is not None:
149150
_make_asyncio_fixture_function(fixture_function, loop_scope)
150151
return pytest.fixture(fixture_function, **kwargs)
@@ -163,9 +164,7 @@ def _is_asyncio_fixture_function(obj: Any) -> bool:
163164
return getattr(obj, "_force_asyncio_fixture", False)
164165

165166

166-
def _make_asyncio_fixture_function(
167-
obj: Any, loop_scope: Union[_ScopeName, None]
168-
) -> None:
167+
def _make_asyncio_fixture_function(obj: Any, loop_scope: _ScopeName | None) -> None:
169168
if hasattr(obj, "__func__"):
170169
# instance method, check the function object
171170
obj = obj.__func__
@@ -288,7 +287,7 @@ def _add_kwargs(
288287
return ret
289288

290289

291-
def _perhaps_rebind_fixture_func(func: _T, instance: Optional[Any]) -> _T:
290+
def _perhaps_rebind_fixture_func(func: _T, instance: Any | None) -> _T:
292291
if instance is not None:
293292
# The fixture needs to be bound to the actual request.instance
294293
# so it is bound to the same object as the test method.
@@ -388,9 +387,7 @@ class PytestAsyncioFunction(Function):
388387
"""Base class for all test functions managed by pytest-asyncio."""
389388

390389
@classmethod
391-
def item_subclass_for(
392-
cls, item: Function, /
393-
) -> Union[type["PytestAsyncioFunction"], None]:
390+
def item_subclass_for(cls, item: Function, /) -> type[PytestAsyncioFunction] | None:
394391
"""
395392
Returns a subclass of PytestAsyncioFunction if there is a specialized subclass
396393
for the specified function item.
@@ -525,10 +522,8 @@ def runtest(self) -> None:
525522
# see https://github.com/pytest-dev/pytest/issues/11307
526523
@pytest.hookimpl(specname="pytest_pycollect_makeitem", tryfirst=True)
527524
def pytest_pycollect_makeitem_preprocess_async_fixtures(
528-
collector: Union[pytest.Module, pytest.Class], name: str, obj: object
529-
) -> Union[
530-
pytest.Item, pytest.Collector, list[Union[pytest.Item, pytest.Collector]], None
531-
]:
525+
collector: pytest.Module | pytest.Class, name: str, obj: object
526+
) -> pytest.Item | pytest.Collector | list[pytest.Item | pytest.Collector] | None:
532527
"""A pytest hook to collect asyncio coroutines."""
533528
if not collector.funcnamefilter(name):
534529
return None
@@ -540,20 +535,17 @@ def pytest_pycollect_makeitem_preprocess_async_fixtures(
540535
# see https://github.com/pytest-dev/pytest/issues/11307
541536
@pytest.hookimpl(specname="pytest_pycollect_makeitem", hookwrapper=True)
542537
def pytest_pycollect_makeitem_convert_async_functions_to_subclass(
543-
collector: Union[pytest.Module, pytest.Class], name: str, obj: object
538+
collector: pytest.Module | pytest.Class, name: str, obj: object
544539
) -> Generator[None, pluggy.Result, None]:
545540
"""
546541
Converts coroutines and async generators collected as pytest.Functions
547542
to AsyncFunction items.
548543
"""
549544
hook_result = yield
550545
try:
551-
node_or_list_of_nodes: Union[
552-
pytest.Item,
553-
pytest.Collector,
554-
list[Union[pytest.Item, pytest.Collector]],
555-
None,
556-
] = hook_result.get_result()
546+
node_or_list_of_nodes: (
547+
pytest.Item | pytest.Collector | list[pytest.Item | pytest.Collector] | None
548+
) = hook_result.get_result()
557549
except BaseException as e:
558550
hook_result.force_exception(e)
559551
return
@@ -592,7 +584,7 @@ def pytest_pycollect_makeitem_convert_async_functions_to_subclass(
592584

593585
# A stack used to push package-scoped loops during collection of a package
594586
# and pop those loops during collection of a Module
595-
__package_loop_stack: list[Union[FixtureFunctionMarker, FixtureFunction]] = []
587+
__package_loop_stack: list[FixtureFunctionMarker | FixtureFunction] = []
596588

597589

598590
@pytest.hookimpl
@@ -868,7 +860,7 @@ def _provide_clean_event_loop() -> None:
868860

869861

870862
def _get_event_loop_no_warn(
871-
policy: Optional[AbstractEventLoopPolicy] = None,
863+
policy: AbstractEventLoopPolicy | None = None,
872864
) -> asyncio.AbstractEventLoop:
873865
with warnings.catch_warnings():
874866
warnings.simplefilter("ignore", DeprecationWarning)
@@ -879,7 +871,7 @@ def _get_event_loop_no_warn(
879871

880872

881873
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
882-
def pytest_pyfunc_call(pyfuncitem: Function) -> Optional[object]:
874+
def pytest_pyfunc_call(pyfuncitem: Function) -> object | None:
883875
"""
884876
Pytest hook called before a test case is run.
885877
@@ -999,7 +991,7 @@ def _get_marked_loop_scope(asyncio_marker: Mark) -> _ScopeName:
999991
return scope
1000992

1001993

1002-
def _retrieve_scope_root(item: Union[Collector, Item], scope: str) -> Collector:
994+
def _retrieve_scope_root(item: Collector | Item, scope: str) -> Collector:
1003995
node_type_by_scope = {
1004996
"class": Class,
1005997
"module": Module,

tests/async_fixtures/test_async_fixtures.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import asyncio
24
import unittest.mock
35

tests/async_fixtures/test_async_fixtures_scope.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
module-scoped too.
44
"""
55

6+
from __future__ import annotations
7+
68
import asyncio
79

810
import pytest

tests/async_fixtures/test_async_fixtures_with_finalizer.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import asyncio
24
import functools
35

tests/async_fixtures/test_async_gen_fixtures.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import unittest.mock
24

35
import pytest

tests/async_fixtures/test_nested.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import asyncio
24

35
import pytest

tests/async_fixtures/test_parametrized_loop.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
from pytest import Pytester

tests/async_fixtures/test_shared_module_fixture.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
from pytest import Pytester

tests/conftest.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import asyncio
24

35
import pytest

tests/hypothesis/test_base.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
sync shim for Hypothesis.
44
"""
55

6+
from __future__ import annotations
7+
68
from textwrap import dedent
79

810
import pytest

tests/loop_fixture_scope/conftest.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import asyncio
24

35
import pytest

tests/loop_fixture_scope/test_loop_fixture_scope.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Unit tests for overriding the event loop with a larger scoped one."""
22

3+
from __future__ import annotations
4+
35
import asyncio
46

57
import pytest

tests/markers/test_class_scope.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Test if pytestmark works when defined on a class."""
22

3+
from __future__ import annotations
4+
35
import asyncio
46
from textwrap import dedent
57

tests/markers/test_function_scope.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
from pytest import Pytester

tests/markers/test_invalid_arguments.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
import pytest

tests/markers/test_module_scope.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
from pytest import Pytester

tests/markers/test_package_scope.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
from pytest import Pytester

tests/markers/test_session_scope.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
from pytest import Pytester

tests/modes/test_auto_mode.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
from pytest import Pytester

tests/modes/test_strict_mode.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
from pytest import Pytester

tests/test_asyncio_fixture.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import asyncio
24
from textwrap import dedent
35

tests/test_asyncio_mark.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
from pytest import Pytester

tests/test_dependent_fixtures.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import asyncio
24

35
import pytest

tests/test_doctest.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
from pytest import Pytester

tests/test_event_loop_fixture.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
from pytest import Pytester

tests/test_event_loop_fixture_finalizer.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
from pytest import Pytester

tests/test_event_loop_fixture_override_deprecation.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
from pytest import Pytester

tests/test_explicit_event_loop_fixture_request.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
from pytest import Pytester

tests/test_fixture_loop_scopes.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
import pytest

tests/test_import.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
from pytest import Pytester

tests/test_is_async_test.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
from pytest import Pytester

tests/test_multiloop.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from textwrap import dedent
24

35
from pytest import Pytester

0 commit comments

Comments
 (0)