special case _evaluate
This commit is contained in:
parent
7416bf3197
commit
3630537da5
@ -21,6 +21,7 @@ from typing import (
|
|||||||
Callable,
|
Callable,
|
||||||
ClassVar,
|
ClassVar,
|
||||||
Dict,
|
Dict,
|
||||||
|
ForwardRef,
|
||||||
FrozenSet,
|
FrozenSet,
|
||||||
Generic,
|
Generic,
|
||||||
Iterable,
|
Iterable,
|
||||||
@ -30,7 +31,6 @@ from typing import (
|
|||||||
Optional,
|
Optional,
|
||||||
Set,
|
Set,
|
||||||
Tuple,
|
Tuple,
|
||||||
ForwardRef,
|
|
||||||
Type,
|
Type,
|
||||||
TypeVar,
|
TypeVar,
|
||||||
Union,
|
Union,
|
||||||
@ -763,9 +763,24 @@ class Var(Generic[VAR_TYPE]):
|
|||||||
|
|
||||||
if isinstance(fixed_type, ForwardRef):
|
if isinstance(fixed_type, ForwardRef):
|
||||||
try:
|
try:
|
||||||
fixed_type = fixed_type._evaluate(globals(), locals(), set())
|
globalns = globals()
|
||||||
except Exception:
|
localns = locals()
|
||||||
raise TypeError(f"Could not resolve ForwardRef: {fixed_type}")
|
# This is very similar to pydantic/typing.py:evaluate_forwardref
|
||||||
|
if sys.version_info < (3, 12, 4):
|
||||||
|
fixed_type = fixed_type._evaluate(globalns, localns)
|
||||||
|
elif sys.version_info < (3, 12, 8):
|
||||||
|
fixed_type = fixed_type._evaluate(
|
||||||
|
globalns, localns, recursive_guard=set()
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
fixed_type = fixed_type._evaluate(
|
||||||
|
globalns=globalns,
|
||||||
|
localns=localns,
|
||||||
|
type_params=(), # type: ignore[arg-type]
|
||||||
|
recursive_guard=frozenset(),
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
raise TypeError(f"Could not resolve ForwardRef: {fixed_type}") from e
|
||||||
|
|
||||||
if fixed_type in types.UnionTypes:
|
if fixed_type in types.UnionTypes:
|
||||||
inner_types = get_args(var_type)
|
inner_types = get_args(var_type)
|
||||||
|
Loading…
Reference in New Issue
Block a user