Skip to content

Commit 188fff3

Browse files
committed
Fix agnosticcontextmanager typing by using ParamSpec from typing_extensions
1 parent 59b225f commit 188fff3

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

opentelemetry-api/src/opentelemetry/util/_decorator.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@
1515
import asyncio
1616
import contextlib
1717
import functools
18-
import typing
19-
from typing import Callable, Generic, Iterator, TypeVar
18+
from typing import TYPE_CHECKING, Callable, Generic, Iterator, TypeVar
2019

2120
V = TypeVar("V")
2221
R = TypeVar("R") # Return type
2322
Pargs = TypeVar("Pargs") # Generic type for arguments
2423
Pkwargs = TypeVar("Pkwargs") # Generic type for arguments
2524

26-
if hasattr(typing, "ParamSpec"):
27-
# only available in python 3.10+
28-
# https://peps.python.org/pep-0612/
29-
P = typing.ParamSpec("P") # Generic type for all arguments
25+
# We don't actually depend on typing_extensions but we can use it in CI with this conditional
26+
# import. ParamSpec can be imported directly from typing after python 3.9 is dropped
27+
# https://peps.python.org/pep-0612/.
28+
if TYPE_CHECKING:
29+
from typing_extensions import ParamSpec
30+
31+
P = ParamSpec("P") # Generic type for all arguments
3032

3133

3234
class _AgnosticContextManager(

0 commit comments

Comments
 (0)