Skip to content

Commit 2a92f5c

Browse files
committed
Improve expandtype
1 parent 74e627e commit 2a92f5c

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

mypy/expandtype.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class ExpandTypeVisitor(TrivialSyntheticTypeTranslator):
186186

187187
def __init__(self, variables: Mapping[TypeVarId, Type]) -> None:
188188
self.variables = variables
189-
self.recursive_guard: set[Type] = set()
189+
self.recursive_guard: set[Type | tuple[int, Type]] = set()
190190

191191
def visit_unbound_type(self, t: UnboundType) -> Type:
192192
return t
@@ -231,13 +231,11 @@ def visit_type_var(self, t: TypeVarType) -> Type:
231231
t = t.copy_modified(upper_bound=t.upper_bound.accept(self))
232232
repl = self.variables.get(t.id, t)
233233

234-
if has_type_vars(repl) and not isinstance(repl, (TypeVarType, Instance)):
235-
if repl in self.recursive_guard or isinstance(repl, (TypeVarType, CallableType)):
234+
if has_type_vars(repl) and not isinstance(repl, Instance):
235+
if repl in self.recursive_guard: # or isinstance(repl, CallableType):
236236
return repl
237237
self.recursive_guard.add(repl)
238238
repl = repl.accept(self)
239-
if t.has_default():
240-
repl = t.copy_modified(default=repl)
241239

242240
if isinstance(repl, Instance):
243241
# TODO: do we really need to do this?
@@ -251,15 +249,11 @@ def visit_param_spec(self, t: ParamSpecType) -> Type:
251249
self.variables.get(t.id, t.copy_modified(prefix=Parameters([], [], [])))
252250
)
253251

254-
while True:
255-
if has_param_specs(repl) and not isinstance(repl, (ParamSpecType, Instance)):
256-
if repl in self.recursive_guard:
257-
break
258-
self.recursive_guard.add(repl)
259-
repl = repl.accept(self)
260-
if t.has_default():
261-
repl = t.copy_modified(default=repl)
262-
break
252+
if has_param_specs(repl) and not isinstance(repl, Instance):
253+
if (t.flavor, repl) in self.recursive_guard:
254+
return repl
255+
self.recursive_guard.add((t.flavor, repl))
256+
repl = repl.accept(self)
263257

264258
if isinstance(repl, Instance):
265259
# TODO: what does prefix mean in this case?

0 commit comments

Comments
 (0)