Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.d/1394.changed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Only import ``asyncio.AbstractEventLoopPolicy`` for type checking to avoid raising
a DeprecationWarning.
8 changes: 7 additions & 1 deletion pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import sys
import traceback
import warnings
from asyncio import AbstractEventLoop, AbstractEventLoopPolicy
from asyncio import AbstractEventLoop
from collections.abc import (
AsyncIterator,
Awaitable,
Expand All @@ -25,6 +25,7 @@
)
from types import AsyncGeneratorType, CoroutineType
from typing import (
TYPE_CHECKING,
Any,
Literal,
ParamSpec,
Expand Down Expand Up @@ -61,6 +62,11 @@
else:
from typing_extensions import TypeIs

if TYPE_CHECKING:
# AbstractEventLoopPolicy is deprecated and scheduled for removal in Python 3.16
# Import it for type checking only to avoid raising a DeprecationWarning.
from asyncio import AbstractEventLoopPolicy

_ScopeName = Literal["session", "package", "module", "class", "function"]
_R = TypeVar("_R", bound=Awaitable[Any] | AsyncIterator[Any])
_P = ParamSpec("_P")
Expand Down
Loading