Skip to content

New semantic analyzer: Various small updates #6246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 7 additions & 1 deletion mypy/newsemanal/semanal_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@


def semantic_analysis_for_scc(graph: 'Graph', scc: List[str]) -> None:
# Assume reachability analysis has already been performed.
"""Perform semantic analysis for all modules in a SCC (import cycle).

Assume that reachability analysis has already been performed.
"""
# Note that functions can't define new module-level attributes
# using 'global x', since module top levels are fully processed
# before functions. This limitation is unlikely to go away soon.
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
9 changes: 9 additions & 0 deletions test-data/unit/check-newsemanal.test
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ 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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer an error in both files, but at least one is also OK.

[file b.py]
# TODO: Could we generate an error here as well?
from a import bad

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