Skip to content

Commit b60bedf

Browse files
committed
Fix typing
1 parent a1dc8e8 commit b60bedf

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

mypy/applytype.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,18 @@ def apply_generic_arguments(
147147
# TODO: move apply_poly() logic from checkexpr.py here when new inference
148148
# becomes universally used (i.e. in all passes + in unification).
149149
# With this new logic we can actually *add* some new free variables.
150-
remaining_tvars = [expand_type(tv, id_to_type) for tv in tvars if tv.id not in id_to_type]
150+
remaining_tvars: list[TypeVarLikeType] = []
151+
for tv in tvars:
152+
if tv.id in id_to_type:
153+
continue
154+
if not tv.has_default():
155+
remaining_tvars.append(tv)
156+
continue
157+
# TypeVarLike isn't in id_to_type mapping.
158+
# Only expand the TypeVar default here.
159+
typ = expand_type(tv, id_to_type)
160+
assert isinstance(typ, TypeVarLikeType)
161+
remaining_tvars.append(typ)
151162

152163
return callable.copy_modified(
153164
ret_type=expand_type(callable.ret_type, id_to_type),

mypy/semanal.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,13 +1954,14 @@ class Foo(Bar, Generic[T]): ...
19541954
del base_type_exprs[i]
19551955
tvar_defs: list[TypeVarLikeType] = []
19561956
for name, tvar_expr in declared_tvars:
1957-
if isinstance(tvar_expr.default, UnboundType):
1957+
tvar_expr_default = tvar_expr.default
1958+
if isinstance(tvar_expr_default, UnboundType):
19581959
# Assumption here is that the names cannot be duplicated
19591960
# TODO: - detect out of order and self-referencing typevars
19601961
# - nested default types, e.g. list[T1]
19611962
for fullname, type_var in self.tvar_scope.scope.items():
19621963
type_var_name = fullname.rpartition(".")[2]
1963-
if tvar_expr.default.name == type_var_name:
1964+
if tvar_expr_default.name == type_var_name:
19641965
tvar_expr.default = type_var
19651966
tvar_def = self.tvar_scope.bind_new(name, tvar_expr)
19661967
tvar_defs.append(tvar_def)

0 commit comments

Comments
 (0)