|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -from typing import Iterable, Mapping, Sequence, TypeVar, cast |
| 3 | +from typing import Iterable, Mapping, Sequence, TypeVar, cast, overload |
4 | 4 |
|
5 | 5 | from mypy.types import ( |
6 | 6 | AnyType, |
|
37 | 37 | from mypy.typevartuples import split_with_instance, split_with_prefix_and_suffix |
38 | 38 |
|
39 | 39 |
|
| 40 | +@overload |
| 41 | +def expand_type(typ: ProperType, env: Mapping[TypeVarId, Type]) -> ProperType: |
| 42 | + ... |
| 43 | + |
| 44 | + |
| 45 | +@overload |
| 46 | +def expand_type(typ: Type, env: Mapping[TypeVarId, Type]) -> Type: |
| 47 | + ... |
| 48 | + |
| 49 | + |
40 | 50 | def expand_type(typ: Type, env: Mapping[TypeVarId, Type]) -> Type: |
41 | 51 | """Substitute any type variable references in a type given by a type |
42 | 52 | environment. |
43 | 53 | """ |
44 | | - # TODO: use an overloaded signature? (ProperType stays proper after expansion.) |
45 | 54 | return typ.accept(ExpandTypeVisitor(env)) |
46 | 55 |
|
47 | 56 |
|
| 57 | +@overload |
| 58 | +def expand_type_by_instance(typ: ProperType, instance: Instance) -> ProperType: |
| 59 | + ... |
| 60 | + |
| 61 | + |
| 62 | +@overload |
| 63 | +def expand_type_by_instance(typ: Type, instance: Instance) -> Type: |
| 64 | + ... |
| 65 | + |
| 66 | + |
48 | 67 | def expand_type_by_instance(typ: Type, instance: Instance) -> Type: |
49 | 68 | """Substitute type variables in type using values from an Instance. |
50 | 69 | Type variables are considered to be bound by the class declaration.""" |
51 | | - # TODO: use an overloaded signature? (ProperType stays proper after expansion.) |
52 | 70 | if not instance.args: |
53 | 71 | return typ |
54 | 72 | else: |
@@ -87,7 +105,6 @@ def freshen_function_type_vars(callee: F) -> F: |
87 | 105 | tvs = [] |
88 | 106 | tvmap: dict[TypeVarId, Type] = {} |
89 | 107 | for v in callee.variables: |
90 | | - # TODO(PEP612): fix for ParamSpecType |
91 | 108 | if isinstance(v, TypeVarType): |
92 | 109 | tv: TypeVarLikeType = TypeVarType.new_unification_variable(v) |
93 | 110 | elif isinstance(v, TypeVarTupleType): |
|
0 commit comments