Skip to content

Commit

Permalink
fix: satisfy type checker for non-3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
autumnjolitz committed Jun 25, 2024
1 parent e40f811 commit 2ce45fd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions instruct/compat.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import sys
import typing
from contextlib import suppress
from typing import NewType, Any
from typing import NewType, Any, TypeVar as IntTypeVar, Union

from typing_extensions import get_origin, get_args
from typing_extensions import TypeVar as ExtTypeVar

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

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

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

else:

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


Expand Down

0 comments on commit 2ce45fd

Please sign in to comment.