Skip to content

Commit a395e85

Browse files
committed
New semantic analyzer: Various small updates
These respond to some review feedback to #6240.
1 parent 4c7bed9 commit a395e85

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

mypy/newsemanal/semanal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2640,7 +2640,7 @@ def analyze_types(self, items: List[Expression]) -> List[Type]:
26402640
if analyzed is not None:
26412641
result.append(analyzed)
26422642
else:
2643-
# TODO: Is this the right thing to do?
2643+
# TODO: Is this the right thing to do? Or maybe return Optional[List[Type]]?
26442644
result.append(AnyType(TypeOfAny.from_error))
26452645
except TypeTranslationError:
26462646
self.fail('Type expected', node)

mypy/newsemanal/semanal_main.py

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
def semantic_analysis_for_scc(graph: 'Graph', scc: List[str]) -> None:
1919
# Assume reachability analysis has already been performed.
20+
#
21+
# Note that functions can't define new module-level attributes,
22+
# since module top levels are fully processed before functions.
2023
process_top_levels(graph, scc)
2124
process_functions(graph, scc)
2225

mypy/plugin.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,12 @@ def anal_type(self, t: Type, *,
182182
allow_unbound_tvars: bool = False,
183183
report_invalid_types: bool = True,
184184
third_pass: bool = False) -> Optional[Type]:
185-
"""Analyze an unbound type."""
185+
"""Analyze an unbound type.
186+
187+
Return None if the some part of the type is not ready yet (only
188+
happens with the new semantic analyzer). In this case the current
189+
target being analyzed will be deferred and analyzed again.
190+
"""
186191
raise NotImplementedError
187192

188193
@abstractmethod

test-data/unit/check-newsemanal.test

+8
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ from b import bad # E: Module 'b' has no attribute 'bad'
8080
[file b.py]
8181
from a import bad2 # E: Module 'a' has no attribute 'bad2'
8282

83+
[case testNewAnalyzerTypeAnnotationCycle4]
84+
# flags: --new-semantic-analyzer
85+
import b
86+
[file a.py]
87+
from b import bad # E: Module 'b' has no attribute 'bad'
88+
[file b.py]
89+
from a import bad
90+
8391
[case testNewAnalyzerSimpleFunction]
8492
# flags: --new-semantic-analyzer
8593
def f(x: int) -> str:

0 commit comments

Comments
 (0)