Skip to content

Commit 3586c99

Browse files
Fix circular import by removing import from mypy.suggestions and inlining ReturnTypeFinder
1 parent 792ac76 commit 3586c99

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

mypy/checker.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@
169169
unify_generic_callable,
170170
)
171171
from mypy.traverser import TraverserVisitor, all_return_statements, has_return_statement
172-
from mypy.suggestions import get_return_types
173172
from mypy.treetransform import TransformVisitor
174173
from mypy.typeanal import check_for_explicit_any, has_any_from_unimported_type, make_optional_type
175174
from mypy.typeops import (
@@ -1620,7 +1619,23 @@ def is_unannotated_any(t: Type) -> bool:
16201619
# Collect return types from return statements
16211620
# Use the master type map (first in stack) where final types are stored
16221621
# At this point in type checking, return statement types should be in the master map
1623-
return_types_list = get_return_types(self._type_maps[0], item)
1622+
# Inline get_return_types to avoid circular import with mypy.suggestions
1623+
class ReturnTypeFinder(TraverserVisitor):
1624+
def __init__(self, typemap: dict[Expression, Type]) -> None:
1625+
self.typemap = typemap
1626+
self.return_types: list[Type] = []
1627+
1628+
def visit_return_stmt(self, o: ReturnStmt) -> None:
1629+
if o.expr is not None and o.expr in self.typemap:
1630+
self.return_types.append(self.typemap[o.expr])
1631+
1632+
def visit_func_def(self, o: FuncDef) -> None:
1633+
# Skip nested functions
1634+
pass
1635+
1636+
finder = ReturnTypeFinder(self._type_maps[0])
1637+
item.body.accept(finder)
1638+
return_types_list = finder.return_types
16241639

16251640
if return_types_list:
16261641
# Create union of all return types

0 commit comments

Comments
 (0)