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)
| 18 | |
| 19 | |
| 20 | def 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 | |
| 65 | def fill_typevars_with_any(typ: TypeInfo) -> Instance | TupleType: |
no test coverage detected
searching dependent graphs…