MCPcopy Index your code
hub / github.com/python/mypy / fill_typevars

Function fill_typevars

mypy/typevars.py:20–62  ·  view source on GitHub ↗

For a non-generic type, return instance type representing the type. For a generic G type with parameters T1, .., Tn, return G[T1, ..., Tn].

(typ: TypeInfo)

Source from the content-addressed store, hash-verified

18
19
20def fill_typevars(typ: TypeInfo) -> Instance | TupleType:
21 """For a non-generic type, return instance type representing the type.
22
23 For a generic G type with parameters T1, .., Tn, return G[T1, ..., Tn].
24 """
25 tvs: list[Type] = []
26 # TODO: why do we need to keep both typ.type_vars and typ.defn.type_vars?
27 for i in range(len(typ.defn.type_vars)):
28 tv: TypeVarLikeType | UnpackType = typ.defn.type_vars[i]
29 # Change the line number
30 if isinstance(tv, TypeVarType):
31 tv = tv.copy_modified(line=-1, column=-1)
32 elif isinstance(tv, TypeVarTupleType):
33 tv = UnpackType(
34 TypeVarTupleType(
35 tv.name,
36 tv.fullname,
37 tv.id,
38 tv.upper_bound,
39 tv.tuple_fallback,
40 tv.default,
41 line=-1,
42 column=-1,
43 )
44 )
45 else:
46 assert isinstance(tv, ParamSpecType)
47 tv = ParamSpecType(
48 tv.name,
49 tv.fullname,
50 tv.id,
51 tv.flavor,
52 tv.upper_bound,
53 tv.default,
54 line=-1,
55 column=-1,
56 )
57 tvs.append(tv)
58 inst = Instance(typ, tvs)
59 # TODO: do we need to also handle typeddict_type here and below?
60 if typ.tuple_type is None:
61 return inst
62 return typ.tuple_type.copy_modified(fallback=inst)
63
64
65def fill_typevars_with_any(typ: TypeInfo) -> Instance | TupleType:

Callers 15

node_type_from_baseMethod · 0.90
_super_arg_typesMethod · 0.90
get_self_typeFunction · 0.90
class_callableFunction · 0.90
map_type_from_supertypeFunction · 0.90
supported_self_typeFunction · 0.90
callable_typeFunction · 0.90
setup_self_typeMethod · 0.90

Calls 10

copy_modifiedMethod · 0.95
UnpackTypeClass · 0.90
TypeVarTupleTypeClass · 0.90
ParamSpecTypeClass · 0.90
InstanceClass · 0.90
rangeClass · 0.85
lenFunction · 0.85
isinstanceFunction · 0.85
appendMethod · 0.80
copy_modifiedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…