Skip to content

Commit 2db9dc3

Browse files
rwbartongvanrossum
authored andcommitted
Remove bound_vars field of CallableType (#1375)
This field was effectively unused since the removal of the runtime type checking target in commit 6dca530 "Remove obsolete transform-related code".
1 parent 388be20 commit 2db9dc3

File tree

7 files changed

+47
-119
lines changed

7 files changed

+47
-119
lines changed

mypy/applytype.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,11 @@ def apply_generic_arguments(callable: CallableType, types: List[Type],
4646
# Apply arguments to argument types.
4747
arg_types = [expand_type(at, id_to_type) for at in callable.arg_types]
4848

49-
bound_vars = [(tv.id, id_to_type[tv.id])
50-
for tv in tvars
51-
if tv.id in id_to_type]
52-
5349
# The callable may retain some type vars if only some were applied.
5450
remaining_tvars = [tv for tv in tvars if tv.id not in id_to_type]
5551

5652
return callable.copy_modified(
5753
arg_types=arg_types,
5854
ret_type=expand_type(callable.ret_type, id_to_type),
5955
variables=remaining_tvars,
60-
bound_vars=callable.bound_vars + bound_vars,
6156
)

mypy/expandtype.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,7 @@ def expand_type_by_instance(typ: Type, instance: Instance) -> Type:
2424
variables = {} # type: Dict[int, Type]
2525
for i in range(len(instance.args)):
2626
variables[i + 1] = instance.args[i]
27-
typ = expand_type(typ, variables)
28-
if isinstance(typ, CallableType):
29-
bounds = [] # type: List[Tuple[int, Type]]
30-
for j in range(len(instance.args)):
31-
bounds.append((j + 1, instance.args[j]))
32-
typ = update_callable_implicit_bounds(cast(CallableType, typ), bounds)
33-
else:
34-
pass
35-
return typ
27+
return expand_type(typ, variables)
3628

3729

3830
class ExpandTypeVisitor(TypeVisitor[Type]):
@@ -83,8 +75,7 @@ def visit_type_var(self, t: TypeVarType) -> Type:
8375

8476
def visit_callable_type(self, t: CallableType) -> Type:
8577
return t.copy_modified(arg_types=self.expand_types(t.arg_types),
86-
ret_type=t.ret_type.accept(self),
87-
bound_vars=self.expand_bound_vars(t.bound_vars))
78+
ret_type=t.ret_type.accept(self))
8879

8980
def visit_overloaded(self, t: Overloaded) -> Type:
9081
items = [] # type: List[CallableType]
@@ -106,16 +97,3 @@ def expand_types(self, types: List[Type]) -> List[Type]:
10697
for t in types:
10798
a.append(t.accept(self))
10899
return a
109-
110-
def expand_bound_vars(
111-
self, types: List[Tuple[int, Type]]) -> List[Tuple[int, Type]]:
112-
a = [] # type: List[Tuple[int, Type]]
113-
for id, t in types:
114-
a.append((id, t.accept(self)))
115-
return a
116-
117-
118-
def update_callable_implicit_bounds(
119-
t: CallableType, arg_types: List[Tuple[int, Type]]) -> CallableType:
120-
# FIX what if there are existing bounds?
121-
return t.copy_modified(bound_vars=arg_types)

mypy/fixup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ def visit_callable_type(self, ct: CallableType) -> None:
165165
for val in v.values:
166166
val.accept(self)
167167
v.upper_bound.accept(self)
168-
for i, t in ct.bound_vars:
169-
t.accept(self)
170168

171169
def visit_ellipsis_type(self, e: EllipsisType) -> None:
172170
pass # Nothing to descend into.

mypy/parse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ def construct_function_type(self, args: List[Argument], ret_type: Type,
800800
arg_kinds = [arg.kind for arg in args]
801801
arg_names = [arg.variable.name() for arg in args]
802802
return CallableType(arg_types, arg_kinds, arg_names, ret_type, None, name=None,
803-
variables=None, bound_vars=[], line=line)
803+
variables=None, line=line)
804804

805805
# Parsing statements
806806

mypy/test/data/typexport-basic.test

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def g() -> None:
309309
a = None # type: A[B]
310310
f = a.f
311311
[out]
312-
MemberExpr(9) : def [1:B] () -> B
312+
MemberExpr(9) : def () -> B
313313

314314
[case testImplicitBoundTypeVarsForSelfMethodReference]
315315
from typing import TypeVar, Generic
@@ -319,7 +319,7 @@ class A(Generic[T]):
319319
self.f()
320320
[out]
321321
CallExpr(5) : T`1
322-
MemberExpr(5) : def [1:T`1] () -> T`1
322+
MemberExpr(5) : def () -> T`1
323323
NameExpr(5) : A[T`1]
324324

325325
[case testGenericFunctionCallWithTypeApp-skip]
@@ -335,13 +335,13 @@ def f(a: T) -> Tuple[T, T]: pass
335335
CallExpr(5) : A
336336
CallExpr(5) : Tuple[A, A]
337337
NameExpr(5) : def () -> A
338-
NameExpr(5) : def [-1:A] (a: A) -> Tuple[A, A]
339-
TypeApplication(5) : def [-1:A] (a: A) -> Tuple[A, A]
338+
NameExpr(5) : def (a: A) -> Tuple[A, A]
339+
TypeApplication(5) : def (a: A) -> Tuple[A, A]
340340
CallExpr(6) : A
341341
CallExpr(6) : Tuple[Any, Any]
342342
NameExpr(6) : def () -> A
343-
NameExpr(6) : def [-1:Any] (a: Any) -> Tuple[Any, Any]
344-
TypeApplication(6) : def [-1:Any] (a: Any) -> Tuple[Any, Any]
343+
NameExpr(6) : def (a: Any) -> Tuple[Any, Any]
344+
TypeApplication(6) : def (a: Any) -> Tuple[Any, Any]
345345

346346
-- NOTE: Type applications are not supported for generic methods, so the
347347
-- following test cases are commented out.
@@ -358,11 +358,11 @@ TypeApplication(6) : def [-1:Any] (a: Any) -> Tuple[Any, Any]
358358
--[builtins fixtures/tuple.py]
359359
--[out]
360360
--CallExpr(2) : Tuple[A, A]
361-
--MemberExpr(2) : def [-1:A] (A a) -> Tuple[A, A]
362-
--TypeApplication(2) : def [-1:A] (A a) -> Tuple[A, A]
361+
--MemberExpr(2) : def (A a) -> Tuple[A, A]
362+
--TypeApplication(2) : def (A a) -> Tuple[A, A]
363363
--CallExpr(3) : Tuple[Any, Any]
364-
--MemberExpr(3) : def [-1:Any] (any a) -> Tuple[Any, Any]
365-
--TypeApplication(3) : def [-1:Any] (any a) -> Tuple[Any, Any]
364+
--MemberExpr(3) : def (any a) -> Tuple[Any, Any]
365+
--TypeApplication(3) : def (any a) -> Tuple[Any, Any]
366366

367367
--[case testGenericMethodCallInGenericTypeWithTypeApp]
368368
--## CallExpr|MemberExpr|TypeApplication
@@ -380,11 +380,11 @@ TypeApplication(6) : def [-1:Any] (a: Any) -> Tuple[Any, Any]
380380
--[builtins fixtures/tuple.py]
381381
--[out]
382382
--CallExpr(6) : Tuple[C, B]
383-
--MemberExpr(6) : def [1:C, -1:B] (B a) -> Tuple[C, B]
384-
--TypeApplication(6) : def [1:C, -1:B] (B a) -> Tuple[C, B]
383+
--MemberExpr(6) : def (B a) -> Tuple[C, B]
384+
--TypeApplication(6) : def (B a) -> Tuple[C, B]
385385
--CallExpr(7) : Tuple[C, Any]
386-
--MemberExpr(7) : def [1:C, -1:Any] (any a) -> Tuple[C, Any]
387-
--TypeApplication(7) : def [1:C, -1:Any] (any a) -> Tuple[C, Any]
386+
--MemberExpr(7) : def (any a) -> Tuple[C, Any]
387+
--TypeApplication(7) : def (any a) -> Tuple[C, Any]
388388

389389
[case testGenericTypeVariableInference]
390390
from typing import TypeVar, Generic
@@ -397,8 +397,8 @@ A(A(B()))
397397
CallExpr(6) : A[A[B]]
398398
CallExpr(6) : A[B]
399399
CallExpr(6) : B
400-
NameExpr(6) : def [-1:A[B]] (a: A[B]) -> A[A[B]]
401-
NameExpr(6) : def [-1:B] (a: B) -> A[B]
400+
NameExpr(6) : def (a: A[B]) -> A[A[B]]
401+
NameExpr(6) : def (a: B) -> A[B]
402402
NameExpr(6) : def () -> B
403403

404404

@@ -417,7 +417,7 @@ class B(A[C]):
417417
self.f(c)
418418
[out]
419419
CallExpr(8) : void
420-
MemberExpr(8) : def [1:C] (a: C)
420+
MemberExpr(8) : def (a: C)
421421
NameExpr(8) : C
422422
NameExpr(8) : B
423423

@@ -433,7 +433,7 @@ class B(A[C, T], Generic[T]):
433433
self.f(c)
434434
[out]
435435
CallExpr(9) : void
436-
MemberExpr(9) : def [1:C, 2:T`1] (a: C)
436+
MemberExpr(9) : def (a: C)
437437
NameExpr(9) : C
438438
NameExpr(9) : B[T`1]
439439

@@ -449,7 +449,7 @@ c = None # type: C
449449
b.f(c)
450450
[out]
451451
CallExpr(9) : void
452-
MemberExpr(9) : def [1:C] (a: C)
452+
MemberExpr(9) : def (a: C)
453453
NameExpr(9) : B
454454
NameExpr(9) : C
455455

@@ -536,10 +536,10 @@ class B: pass
536536
b = None # type: B
537537
[out]
538538
CallExpr(4) : A[B]
539-
NameExpr(4) : def [-1:B] (a: B) -> A[B]
539+
NameExpr(4) : def (a: B) -> A[B]
540540
NameExpr(4) : B
541541
CallExpr(5) : A[builtins.object]
542-
NameExpr(5) : def [-1:builtins.object] (a: builtins.object) -> A[builtins.object]
542+
NameExpr(5) : def (a: builtins.object) -> A[builtins.object]
543543
NameExpr(5) : B
544544

545545
[case testGenericCallInDynamicallyTypedFunction]
@@ -550,7 +550,7 @@ def f():
550550
class A(Generic[T]): pass
551551
[out]
552552
CallExpr(4) : A[Any]
553-
NameExpr(4) : def [-1:Any] () -> A[Any]
553+
NameExpr(4) : def () -> A[Any]
554554

555555
[case testGenericCallInDynamicallyTypedFunction2]
556556
from typing import TypeVar, Generic
@@ -561,7 +561,7 @@ class A(Generic[T]):
561561
def __init__(self, x: T) -> None: pass
562562
[out]
563563
CallExpr(4) : A[Any]
564-
NameExpr(4) : def [-1:Any] (x: Any) -> A[Any]
564+
NameExpr(4) : def (x: Any) -> A[Any]
565565
NameExpr(4) : def () -> Any
566566

567567
[case testGenericCallInDynamicallyTypedFunction3]
@@ -572,7 +572,7 @@ def f():
572572
def g(x: t) -> t: pass
573573
[out]
574574
CallExpr(4) : Any
575-
NameExpr(4) : def [-1:Any] (x: Any) -> Any
575+
NameExpr(4) : def (x: Any) -> Any
576576

577577

578578
-- Generic types and type inference
@@ -623,14 +623,14 @@ class B: pass
623623
class C: pass
624624
[out]
625625
CallExpr(4) : A[B]
626-
NameExpr(4) : def [-1:B] (x: B) -> A[B]
626+
NameExpr(4) : def (x: B) -> A[B]
627627
NameExpr(4) : A[B]
628628
NameExpr(4) : B
629629
NameExpr(5) : A[B]
630630
CallExpr(6) : A[B]
631631
CallExpr(6) : A[C]
632-
NameExpr(6) : def [-1:B] (x: B) -> A[B]
633-
NameExpr(6) : def [-1:C] (x: C) -> A[C]
632+
NameExpr(6) : def (x: B) -> A[B]
633+
NameExpr(6) : def (x: C) -> A[C]
634634
NameExpr(6) : A[B]
635635
NameExpr(6) : A[C]
636636
NameExpr(6) : B
@@ -656,8 +656,8 @@ def g(a: S) -> B[S]: pass
656656
CallExpr(5) : A[C]
657657
CallExpr(5) : B[A[C]]
658658
NameExpr(5) : C
659-
NameExpr(5) : def [-1:C] (a: C) -> A[C]
660-
NameExpr(5) : def [-1:A[C]] (a: A[C]) -> B[A[C]]
659+
NameExpr(5) : def (a: C) -> A[C]
660+
NameExpr(5) : def (a: A[C]) -> B[A[C]]
661661

662662
[case testInferListLiterals]
663663
from typing import List
@@ -688,7 +688,7 @@ def f(a: A) -> B: pass
688688
[builtins fixtures/list.py]
689689
[out]
690690
CallExpr(4) : builtins.list[B]
691-
NameExpr(4) : def [-1:A, -2:B] (f: def (A) -> B, a: builtins.list[A]) -> builtins.list[B]
691+
NameExpr(4) : def (f: def (A) -> B, a: builtins.list[A]) -> builtins.list[B]
692692
NameExpr(5) : def (a: A) -> B
693693
CallExpr(6) : A
694694
ListExpr(6) : builtins.list[A]
@@ -752,7 +752,7 @@ def f(a: A) -> B: pass
752752
[builtins fixtures/list.py]
753753
[out]
754754
CallExpr(5) : builtins.list[B]
755-
NameExpr(5) : def [-1:A, -2:B] (f: def (A) -> B, a: builtins.list[A]) -> builtins.list[B]
755+
NameExpr(5) : def (f: def (A) -> B, a: builtins.list[A]) -> builtins.list[B]
756756
CallExpr(6) : B
757757
FuncExpr(6) : def (A) -> B
758758
NameExpr(6) : def (a: A) -> B
@@ -773,7 +773,7 @@ class B: pass
773773
def f(a: A) -> B: pass
774774
[builtins fixtures/list.py]
775775
[out]
776-
NameExpr(6) : def [-1:A, -2:B] (f: def (A) -> builtins.list[B], a: builtins.list[A]) -> builtins.list[B]
776+
NameExpr(6) : def (f: def (A) -> builtins.list[B], a: builtins.list[A]) -> builtins.list[B]
777777
FuncExpr(7) : def (A) -> builtins.list[B]
778778
ListExpr(7) : builtins.list[B]
779779
NameExpr(7) : def (a: A) -> B
@@ -795,7 +795,7 @@ class A: pass
795795
-- TODO We probably should not silently infer 'Any' types in statically typed
796796
-- context. Perhaps just fail instead?
797797
CallExpr(5) : builtins.list[Any]
798-
NameExpr(5) : def [-1:A, -2:Any] (f: builtins.list[def (A) -> Any], a: builtins.list[A]) -> builtins.list[Any]
798+
NameExpr(5) : def (f: builtins.list[def (A) -> Any], a: builtins.list[A]) -> builtins.list[Any]
799799
FuncExpr(6) : def (A) -> A
800800
ListExpr(6) : builtins.list[def (A) -> Any]
801801
NameExpr(6) : A
@@ -816,7 +816,7 @@ class B: pass
816816
[builtins fixtures/list.py]
817817
[out]
818818
CallExpr(5) : builtins.list[B]
819-
NameExpr(5) : def [-1:A, -2:B] (f: def (A) -> B, a: builtins.list[A]) -> builtins.list[B]
819+
NameExpr(5) : def (f: def (A) -> B, a: builtins.list[A]) -> builtins.list[B]
820820
FuncExpr(6) : def (A) -> B
821821
MemberExpr(6) : B
822822
NameExpr(6) : A
@@ -837,7 +837,7 @@ class B: pass
837837
[builtins fixtures/list.py]
838838
[out]
839839
CallExpr(5) : builtins.list[B]
840-
NameExpr(5) : def [-1:A, -2:B] (f: def (A) -> B, a: builtins.list[A]) -> builtins.list[B]
840+
NameExpr(5) : def (f: def (A) -> B, a: builtins.list[A]) -> builtins.list[B]
841841
NameExpr(6) : builtins.list[A]
842842
FuncExpr(7) : def (A) -> B
843843
MemberExpr(7) : B
@@ -937,7 +937,7 @@ class A:
937937
def f(self, x: t) -> None: pass
938938
A.f(A(), B())
939939
[out]
940-
MemberExpr(7) : def [-1:B] (self: A, x: B)
940+
MemberExpr(7) : def (self: A, x: B)
941941

942942
[case testUnboundMethodOfGenericClass]
943943
## MemberExpr
@@ -951,7 +951,7 @@ a_b = A() # type: A[B]
951951
A.f(a_b, B())
952952
[out]
953953
MemberExpr(7) : def [t] (self: A[t`1], x: t`1)
954-
MemberExpr(9) : def [1:B] (self: A[B], x: B)
954+
MemberExpr(9) : def (self: A[B], x: B)
955955

956956
[case testUnboundOverloadedMethodOfGenericClass]
957957
## CallExpr
@@ -991,7 +991,7 @@ ab = None # type: A[B]
991991
o = None # type: object
992992
A.f(ab, o)
993993
[out]
994-
MemberExpr(10) : def [1:B, -1:builtins.object] (self: A[B], y: builtins.object)
994+
MemberExpr(10) : def (self: A[B], y: builtins.object)
995995

996996

997997
-- Type variables with value restriction
@@ -1006,8 +1006,8 @@ def f(x: T) -> None: pass
10061006
f(1)
10071007
f('x')
10081008
[out]
1009-
NameExpr(5) : def [-1:builtins.int] (x: builtins.int)
1010-
NameExpr(6) : def [-1:builtins.str] (x: builtins.str)
1009+
NameExpr(5) : def (x: builtins.int)
1010+
NameExpr(6) : def (x: builtins.str)
10111011

10121012
[case testTypeVariableWithValueRestrictionAndSubtype]
10131013
## NameExpr|CallExpr
@@ -1019,7 +1019,7 @@ s = None # type: S
10191019
f(s)
10201020
[out]
10211021
CallExpr(7) : builtins.str
1022-
NameExpr(7) : def [-1:builtins.str] (x: builtins.str) -> builtins.str
1022+
NameExpr(7) : def (x: builtins.str) -> builtins.str
10231023
NameExpr(7) : S
10241024

10251025

@@ -1108,7 +1108,7 @@ IntExpr(13) : builtins.int
11081108
ListExpr(13) : builtins.list[builtins.int]
11091109
CallExpr(14) : void
11101110
NameExpr(14) : def (s: builtins.int) -> builtins.int
1111-
NameExpr(14) : def [-1:builtins.int, -2:builtins.int] (fun: def (builtins.int) -> builtins.int, iter: builtins.list[builtins.int])
1111+
NameExpr(14) : def (fun: def (builtins.int) -> builtins.int, iter: builtins.list[builtins.int])
11121112
NameExpr(15) : builtins.list[builtins.int]
11131113

11141114

mypy/typeanal.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ def visit_callable_type(self, t: CallableType) -> Type:
180180
return t.copy_modified(arg_types=self.anal_array(t.arg_types),
181181
ret_type=t.ret_type.accept(self),
182182
fallback=t.fallback or self.builtin_type('builtins.function'),
183-
variables=self.anal_var_defs(t.variables),
184-
bound_vars=self.anal_bound_vars(t.bound_vars))
183+
variables=self.anal_var_defs(t.variables))
185184

186185
def visit_tuple_type(self, t: TupleType) -> Type:
187186
if t.implicit:
@@ -247,13 +246,6 @@ def anal_array(self, a: List[Type]) -> List[Type]:
247246
res.append(t.accept(self))
248247
return res
249248

250-
def anal_bound_vars(self,
251-
a: List[Tuple[int, Type]]) -> List[Tuple[int, Type]]:
252-
res = [] # type: List[Tuple[int, Type]]
253-
for id, t in a:
254-
res.append((id, t.accept(self)))
255-
return res
256-
257249
def anal_var_defs(self, var_defs: List[TypeVarDef]) -> List[TypeVarDef]:
258250
a = [] # type: List[TypeVarDef]
259251
for vd in var_defs:

0 commit comments

Comments
 (0)