Skip to content

Commit 84a5202

Browse files
committed
Remove TupleGetterType
in favour of `api.named_type("collections._tuplegetter")`
1 parent 9cedc4f commit 84a5202

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+146
-220
lines changed

mypy/checkmember.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
ParamSpecType,
6262
PartialType,
6363
ProperType,
64-
TupleGetterType,
6564
TupleType,
6665
Type,
6766
TypedDictType,
@@ -936,20 +935,12 @@ def analyze_var(
936935
return result
937936

938937

939-
def expand_tuplegetter_type_if_needed(typ: Type) -> Type:
940-
proper = get_proper_type(typ)
941-
if isinstance(proper, TupleGetterType):
942-
return proper.typ
943-
return typ
944-
945-
946938
def expand_without_binding(
947939
typ: Type, var: Var, itype: Instance, original_itype: Instance, mx: MemberContext
948940
) -> Type:
949941
if not mx.preserve_type_var_ids:
950942
typ = freshen_all_functions_type_vars(typ)
951943
typ = expand_self_type_if_needed(typ, mx, var, original_itype)
952-
typ = expand_tuplegetter_type_if_needed(typ)
953944
expanded = expand_type_by_instance(typ, itype)
954945
freeze_all_type_vars(expanded)
955946
return expanded

mypy/constraints.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
ParamSpecType,
3737
PartialType,
3838
ProperType,
39-
TupleGetterType,
4039
TupleType,
4140
Type,
4241
TypeAliasType,
@@ -1245,9 +1244,6 @@ def infer_against_overloaded(
12451244
item = find_matching_overload_item(overloaded, template)
12461245
return infer_constraints(template, item, self.direction)
12471246

1248-
def visit_tuplegetter_type(self, template: TupleGetterType) -> list[Constraint]:
1249-
raise NotImplementedError
1250-
12511247
def visit_tuple_type(self, template: TupleType) -> list[Constraint]:
12521248
actual = self.actual
12531249
unpack_index = find_unpack_in_list(template.items)

mypy/copytype.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
ParamSpecType,
1616
PartialType,
1717
ProperType,
18-
TupleGetterType,
1918
TupleType,
2019
TypeAliasType,
2120
TypedDictType,
@@ -104,9 +103,6 @@ def visit_partial_type(self, t: PartialType) -> ProperType:
104103
def visit_callable_type(self, t: CallableType) -> ProperType:
105104
return self.copy_common(t, t.copy_modified())
106105

107-
def visit_tuplegetter_type(self, t: TupleGetterType) -> ProperType:
108-
return self.copy_common(t, TupleGetterType(t.typ))
109-
110106
def visit_tuple_type(self, t: TupleType) -> ProperType:
111107
return self.copy_common(t, TupleType(t.items, t.partial_fallback, implicit=t.implicit))
112108

mypy/erasetype.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
ParamSpecType,
1818
PartialType,
1919
ProperType,
20-
TupleGetterType,
2120
TupleType,
2221
Type,
2322
TypeAliasType,
@@ -116,9 +115,6 @@ def visit_callable_type(self, t: CallableType) -> ProperType:
116115
def visit_overloaded(self, t: Overloaded) -> ProperType:
117116
return t.fallback.accept(self)
118117

119-
def visit_tuplegetter_type(self, t: TupleGetterType) -> ProperType:
120-
raise NotImplementedError
121-
122118
def visit_tuple_type(self, t: TupleType) -> ProperType:
123119
return t.partial_fallback.accept(self)
124120

mypy/expandtype.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
PartialType,
2424
ProperType,
2525
TrivialSyntheticTypeTranslator,
26-
TupleGetterType,
2726
TupleType,
2827
Type,
2928
TypeAliasType,
@@ -457,9 +456,6 @@ def expand_type_tuple_with_unpack(self, typs: tuple[Type, ...]) -> list[Type]:
457456
items.append(item.accept(self))
458457
return items
459458

460-
def visit_tuplegetter_type(self, t: TupleGetterType) -> Type:
461-
return TupleGetterType(t.typ.accept(self))
462-
463459
def visit_tuple_type(self, t: TupleType) -> Type:
464460
items = self.expand_type_list_with_unpack(t.items)
465461
if len(items) == 1:

mypy/fixup.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
Overloaded,
3030
Parameters,
3131
ParamSpecType,
32-
TupleGetterType,
3332
TupleType,
3433
TypeAliasType,
3534
TypedDictType,
@@ -297,9 +296,6 @@ def visit_uninhabited_type(self, o: Any) -> None:
297296
def visit_partial_type(self, o: Any) -> None:
298297
raise RuntimeError("Shouldn't get here", o)
299298

300-
def visit_tuplegetter_type(self, tgt: TupleGetterType) -> None:
301-
tgt.typ.accept(self)
302-
303299
def visit_tuple_type(self, tt: TupleType) -> None:
304300
if tt.items:
305301
for it in tt.items:

mypy/indirection.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@ def visit_overloaded(self, t: types.Overloaded) -> None:
128128
self._visit_type_list(list(t.items))
129129
self._visit(t.fallback)
130130

131-
def visit_tuplegetter_type(self, t: types.TupleGetterType) -> None:
132-
self._visit(t.typ)
133-
134131
def visit_tuple_type(self, t: types.TupleType) -> None:
135132
self._visit_type_list(t.items)
136133
self._visit(t.partial_fallback)

mypy/join.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
ParamSpecType,
3333
PartialType,
3434
ProperType,
35-
TupleGetterType,
3635
TupleType,
3736
Type,
3837
TypeAliasType,
@@ -560,9 +559,6 @@ def join_tuples(self, s: TupleType, t: TupleType) -> list[Type] | None:
560559
items.append(join_types(fi, vi))
561560
return items
562561

563-
def visit_tuplegetter_type(self, t: TupleGetterType) -> ProperType:
564-
raise NotImplementedError
565-
566562
def visit_tuple_type(self, t: TupleType) -> ProperType:
567563
# When given two fixed-length tuples:
568564
# * If they have the same length, join their subtypes item-wise:

mypy/meet.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
ParamSpecType,
3333
PartialType,
3434
ProperType,
35-
TupleGetterType,
3635
TupleType,
3736
Type,
3837
TypeAliasType,
@@ -1040,9 +1039,6 @@ def meet_tuples(self, s: TupleType, t: TupleType) -> list[Type] | None:
10401039
items.append(self.meet(fi, vi))
10411040
return items
10421041

1043-
def visit_tuplegetter_type(self, t: TupleGetterType) -> ProperType:
1044-
raise NotImplementedError
1045-
10461042
def visit_tuple_type(self, t: TupleType) -> ProperType:
10471043
if isinstance(self.s, TupleType):
10481044
items = self.meet_tuples(self.s, t)

mypy/messages.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
ParamSpecType,
8585
PartialType,
8686
ProperType,
87-
TupleGetterType,
8887
TupleType,
8988
Type,
9089
TypeAliasType,
@@ -2665,8 +2664,6 @@ def format_literal_value(typ: LiteralType) -> str:
26652664
else:
26662665
# TODO: better disambiguate ParamSpec name clashes.
26672666
return typ.name_with_suffix()
2668-
elif isinstance(typ, TupleGetterType):
2669-
return f"TupleGetterType[{typ.typ}]"
26702667
elif isinstance(typ, TupleType):
26712668
# Prefer the name of the fallback class (if not tuple), as it's more informative.
26722669
if typ.partial_fallback.type.fullname != "builtins.tuple":

0 commit comments

Comments
 (0)