Skip to content

Commit c478dd1

Browse files
committed
fix(compat): satisfy type checker for Python 3.11 and below
1 parent 9b741ce commit c478dd1

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

instruct/compat.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import sys
22
import typing
33
from contextlib import suppress
4-
from typing import NewType, Any
4+
from typing import NewType, Any, TypeVar as IntTypeVar, Union
55

66
from typing_extensions import get_origin, get_args
7+
from typing_extensions import TypeVar as ExtTypeVar
78

89
if sys.version_info[:2] >= (3, 8):
910
from typing import Protocol, Literal, runtime_checkable, TypedDict
@@ -81,14 +82,14 @@ def bar():
8182

8283
if sys.version_info[:2] >= (3, 13):
8384

84-
def typevar_has_no_default(t: TypeVar) -> TypeGuard[NoDefaultType]:
85+
def typevar_has_no_default(t: Union[IntTypeVar, ExtTypeVar]) -> TypeGuard[NoDefaultType]:
8586
return t.__default__ is NoDefault
8687

8788
else:
8889

89-
def typevar_has_no_default(t: TypeVar) -> TypeGuard[NoDefaultType]:
90+
def typevar_has_no_default(t: Union[IntTypeVar, ExtTypeVar]) -> TypeGuard[NoDefaultType]:
9091
with suppress(AttributeError):
91-
return t.__default__ is NoDefault # type:ignore[attr-defined]
92+
return t.__default__ is NoDefault # type:ignore[union-attr]
9293
return False
9394

9495

0 commit comments

Comments
 (0)