Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion tests/test_type_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ class TB:
y: list[object]


type GetA1[A, B] = A
type GetA2[B, A] = A


def test_eval_arg_order():
d = eval_typing(GetA1[int, str])
assert d is int
d = eval_typing(GetA2[str, int])
assert d is int


def test_type_getattr_union_1():
d = eval_typing(GetAttr[TA | TB, Literal["x"]])
assert d == int | str
Expand Down Expand Up @@ -640,7 +651,7 @@ def test_never_is():
assert d is True


def test_eval_iter():
def test_eval_iter_01():
d = eval_typing(Iter[tuple[int, str]])
assert tuple(d) == (int, str)

Expand Down
15 changes: 14 additions & 1 deletion typemap/type_eval/_eval_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,20 @@ def _eval_applied_type_alias(obj: types.GenericAlias, ctx: EvalContext):

func = obj.evaluate_value

args = tuple(types.CellType(_eval_types(arg, ctx)) for arg in obj.__args__)
# obj.__args__ matches the declared parameter order, but args are expected
# to be in the same order as func.__code__.co_freevars.
args_by_name = dict(
zip(
(p.__name__ for p in obj.__origin__.__type_params__),
obj.__args__,
strict=False,
)
)

args = tuple(
types.CellType(_eval_types(args_by_name[name], ctx))
for name in func.__code__.co_freevars
)
mod = sys.modules[obj.__module__]

with _child_context() as child_ctx:
Expand Down