add support for recursive datatypes

This commit is contained in:
Vasyl Yovdiy 2025-01-16 11:30:58 +01:00
parent e8dd0ae47d
commit 7416bf3197

View File

@ -30,6 +30,7 @@ from typing import (
Optional,
Set,
Tuple,
ForwardRef,
Type,
TypeVar,
Union,
@ -760,6 +761,12 @@ class Var(Generic[VAR_TYPE]):
fixed_type = get_origin(var_type) or var_type
if isinstance(fixed_type, ForwardRef):
try:
fixed_type = fixed_type._evaluate(globals(), locals(), set())
except Exception:
raise TypeError(f"Could not resolve ForwardRef: {fixed_type}")
if fixed_type in types.UnionTypes:
inner_types = get_args(var_type)