Skip to content

Commit 0de370f

Browse files
cdce8pseifertm
authored andcommitted
Import asyncio.AbstractEventLoopPolicy only for type checking
1 parent f0928f5 commit 0de370f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

changelog.d/1394.changed.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Only import ``asyncio.AbstractEventLoopPolicy`` for type checking to avoid raising
2+
a DeprecationWarning.

pytest_asyncio/plugin.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import sys
1313
import traceback
1414
import warnings
15-
from asyncio import AbstractEventLoop, AbstractEventLoopPolicy
15+
from asyncio import AbstractEventLoop
1616
from collections.abc import (
1717
AsyncIterator,
1818
Awaitable,
@@ -25,6 +25,7 @@
2525
)
2626
from types import AsyncGeneratorType, CoroutineType
2727
from typing import (
28+
TYPE_CHECKING,
2829
Any,
2930
Literal,
3031
ParamSpec,
@@ -61,6 +62,11 @@
6162
else:
6263
from typing_extensions import TypeIs
6364

65+
if TYPE_CHECKING:
66+
# AbstractEventLoopPolicy is deprecated and scheduled for removal in Python 3.16
67+
# Import it for type checking only to avoid raising a DeprecationWarning.
68+
from asyncio import AbstractEventLoopPolicy
69+
6470
_ScopeName = Literal["session", "package", "module", "class", "function"]
6571
_R = TypeVar("_R", bound=Awaitable[Any] | AsyncIterator[Any])
6672
_P = ParamSpec("_P")

0 commit comments

Comments
 (0)