Skip to content

Commit 64abca3

Browse files
mnxoidmykhaylo-dudyakdangotbanned
authored
fix: Check typing_extensions.TypeVar(default) exists (#2361)
Co-authored-by: Mykhaylo Dudyak <[email protected]> Co-authored-by: dangotbanned <[email protected]>
1 parent 4144497 commit 64abca3

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

narwhals/_translate.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@
66
from typing import Mapping
77
from typing import Protocol
88

9+
_MIN_TYPING_EXTENSIONS = 4, 4, 0
10+
_TYPING_EXTENSIONS = "typing_extensions"
11+
12+
13+
def _typing_extensions_has_pep_696() -> bool: # pragma: no cover
14+
from importlib.metadata import version
15+
from importlib.util import find_spec
16+
17+
from narwhals.utils import parse_version
18+
19+
if find_spec(_TYPING_EXTENSIONS):
20+
return parse_version(version(_TYPING_EXTENSIONS)) >= _MIN_TYPING_EXTENSIONS
21+
return False
22+
23+
924
if TYPE_CHECKING:
1025
import pyarrow as pa
1126
from typing_extensions import Self
@@ -16,11 +31,10 @@
1631

1732
else: # pragma: no cover
1833
import sys
19-
from importlib.util import find_spec
2034

2135
if sys.version_info >= (3, 13):
2236
from typing import TypeVar
23-
elif find_spec("typing_extensions"):
37+
elif _typing_extensions_has_pep_696():
2438
from typing_extensions import TypeVar
2539
else:
2640
from typing import TypeVar as _TypeVar

0 commit comments

Comments
 (0)