Skip to content

Commit

Permalink
New semantic analyzer: Various small updates
Browse files Browse the repository at this point in the history
These respond to some review feedback to
#6240.
  • Loading branch information
JukkaL committed Jan 24, 2019
1 parent 4c7bed9 commit a395e85
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mypy/newsemanal/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2640,7 +2640,7 @@ def analyze_types(self, items: List[Expression]) -> List[Type]:
if analyzed is not None:
result.append(analyzed)
else:
# TODO: Is this the right thing to do?
# TODO: Is this the right thing to do? Or maybe return Optional[List[Type]]?
result.append(AnyType(TypeOfAny.from_error))
except TypeTranslationError:
self.fail('Type expected', node)
Expand Down
3 changes: 3 additions & 0 deletions mypy/newsemanal/semanal_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

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

Expand Down
7 changes: 6 additions & 1 deletion mypy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@ def anal_type(self, t: Type, *,
allow_unbound_tvars: bool = False,
report_invalid_types: bool = True,
third_pass: bool = False) -> Optional[Type]:
"""Analyze an unbound type."""
"""Analyze an unbound type.
Return None if the some part of the type is not ready yet (only
happens with the new semantic analyzer). In this case the current
target being analyzed will be deferred and analyzed again.
"""
raise NotImplementedError

@abstractmethod
Expand Down
8 changes: 8 additions & 0 deletions test-data/unit/check-newsemanal.test
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ from b import bad # E: Module 'b' has no attribute 'bad'
[file b.py]
from a import bad2 # E: Module 'a' has no attribute 'bad2'

[case testNewAnalyzerTypeAnnotationCycle4]
# flags: --new-semantic-analyzer
import b
[file a.py]
from b import bad # E: Module 'b' has no attribute 'bad'
[file b.py]
from a import bad

[case testNewAnalyzerSimpleFunction]
# flags: --new-semantic-analyzer
def f(x: int) -> str:
Expand Down

0 comments on commit a395e85

Please sign in to comment.