Skip to content

Commit 755b479

Browse files
committed
some fixes (mainly to avoid recursion errors)
1 parent 89d5355 commit 755b479

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

mypy/checker.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@
216216
UnpackType,
217217
find_unpack_in_list,
218218
flatten_nested_unions,
219-
flatten_nested_tuples,
220219
get_proper_type,
221220
get_proper_types,
222221
is_literal_type,
@@ -2937,7 +2936,7 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
29372936
isinstance(lvalue, NameExpr)
29382937
and isinstance(var := lvalue.node, Var)
29392938
):
2940-
self.search_deprecated(var.type, s)
2939+
self.search_deprecated(var.type, s, set())
29412940

29422941
# Avoid type checking type aliases in stubs to avoid false
29432942
# positives about modern type syntax available in stubs such
@@ -7581,17 +7580,17 @@ def warn_deprecated(self, node: SymbolNode | None, context: Context) -> None:
75817580
warn = self.msg.fail if self.options.report_deprecated_as_error else self.msg.note
75827581
warn(deprecated, context, code=codes.DEPRECATED)
75837582

7584-
def search_deprecated(self, typ, s: AssignmentStmt) -> None:
7585-
if isinstance(typ := get_proper_type(typ), Instance):
7586-
self.check_deprecated(typ.type, s)
7587-
for arg in typ.args:
7588-
self.search_deprecated(arg, s)
7589-
elif isinstance(typ, UnionType):
7590-
for subtype in flatten_nested_unions([typ]):
7591-
self.search_deprecated(subtype, s)
7592-
elif isinstance(typ, TupleType):
7593-
for subtype in flatten_types(typ):
7594-
self.search_deprecated(subtype, s)
7583+
def search_deprecated(self, typ: Type | None, s: AssignmentStmt, visited: set[Type]) -> None:
7584+
7585+
if typ not in visited:
7586+
visited.add(typ)
7587+
if isinstance(typ := get_proper_type(typ), Instance):
7588+
self.check_deprecated(typ.type, s)
7589+
for arg in typ.args:
7590+
self.search_deprecated(arg, s, visited)
7591+
elif isinstance(typ, (UnionType, TupleType)):
7592+
for item in typ.items:
7593+
self.search_deprecated(item, s, visited)
75957594

75967595

75977596
class CollectArgTypeVarTypes(TypeTraverserVisitor):

0 commit comments

Comments
 (0)