Skip to content

Commit ebca0cb

Browse files
JukkaLgvanrossum
authored andcommitted
Fix crash during deserialization of callable types (#3660)
The bound type arguments of callables were not fixed up properly.
1 parent 5a046ee commit ebca0cb

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

mypy/fixup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ def visit_callable_type(self, ct: CallableType) -> None:
191191
for val in v.values:
192192
val.accept(self)
193193
v.upper_bound.accept(self)
194+
for arg in ct.bound_args:
195+
if arg:
196+
arg.accept(self)
194197

195198
def visit_overloaded(self, t: Overloaded) -> None:
196199
for ct in t.items():

test-data/unit/check-serialize.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,26 @@ def f(x: int,
124124
[builtins fixtures/dict.pyi]
125125
[out2]
126126

127+
[case testSerializeCallableWithBoundTypeArguments]
128+
import a
129+
[file a.py]
130+
import b
131+
[file a.py.2]
132+
import b
133+
x = b.f
134+
[file b.py]
135+
from typing import TypeVar, Generic
136+
137+
T = TypeVar('T')
138+
139+
class C(Generic[T]):
140+
def f(self, x: T) -> None: pass
141+
142+
c: C[int]
143+
f = c.f
144+
[out]
145+
[out2]
146+
127147
[case testSerializePositionalOnlyArgument]
128148
import a
129149
[file a.py]

0 commit comments

Comments
 (0)