Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge branch 'master' into kwargs-and-tvt
  • Loading branch information
A5rocks authored Jul 10, 2024
commit c6c9feec7c0d80475c0d4a746df88c8876c515e6
13 changes: 1 addition & 12 deletions mypy/erasetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,7 @@ def visit_deleted_type(self, t: DeletedType) -> ProperType:
return t

def visit_instance(self, t: Instance) -> ProperType:
args: list[Type] = []
for tv in t.type.defn.type_vars:
# Valid erasure for *Ts is *tuple[Any, ...], not just Any.
# TODO: try updating this to use TupleType
if isinstance(tv, TypeVarTupleType):
args.append(
UnpackType(
tv.tuple_fallback.copy_modified(args=[AnyType(TypeOfAny.special_form)])
)
)
else:
args.append(AnyType(TypeOfAny.special_form))
args = erased_vars(t.type.defn.type_vars, TypeOfAny.special_form)
return Instance(t.type, args, t.line)

def visit_type_var(self, t: TypeVarType) -> ProperType:
Expand Down
10 changes: 10 additions & 0 deletions mypy/expandtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ def visit_erased_type(self, t: ErasedType) -> Type:

def visit_instance(self, t: Instance) -> Type:
args = self.expand_types_with_unpack(list(t.args))[0]

if isinstance(t.type, FakeInfo):
# The type checker expands function definitions and bodies
# if they depend on constrained type variables but the body
# might contain a tuple type comment (e.g., # type: (int, float)),
# in which case 't.type' is not yet available.
#
# See: https://github.com/python/mypy/issues/16649
return t.copy_modified(args=args)

if t.type.fullname == "builtins.tuple":
# Normalize Tuple[*Tuple[X, ...], ...] -> Tuple[X, ...]
arg = args[0]
Expand Down
12 changes: 1 addition & 11 deletions mypy/typevars.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,7 @@ def fill_typevars(typ: TypeInfo) -> Instance | TupleType:

def fill_typevars_with_any(typ: TypeInfo) -> Instance | TupleType:
"""Apply a correct number of Any's as type arguments to a type."""
args: list[Type] = []
for tv in typ.defn.type_vars:
# Valid erasure for *Ts is *tuple[Any, ...], not just Any.
# TODO: use TupleType
if isinstance(tv, TypeVarTupleType):
args.append(
UnpackType(tv.tuple_fallback.copy_modified(args=[AnyType(TypeOfAny.special_form)]))
)
else:
args.append(AnyType(TypeOfAny.special_form))
inst = Instance(typ, args)
inst = Instance(typ, erased_vars(typ.defn.type_vars, TypeOfAny.special_form))
if typ.tuple_type is None:
return inst
erased_tuple_type = erase_typevars(typ.tuple_type, {tv.id for tv in typ.defn.type_vars})
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.