Skip to content
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

Refactor: Move code out of semantic analyzer pass 2 #4855

Merged
merged 6 commits into from
Apr 4, 2018

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Apr 4, 2018

This moves the semantic analysis of named tuples, TypedDicts, call-based
Enum and NewType to separate modules. I chose these based on these
criteria:

  • The features have a significant amount of code so refactoring seems
    valuable.
  • The features don't interact much with other features.
  • The features are arguably not "core" mypy features.

There are still other bits we could move away in the future.

Also extended the abstract semantic analyzer API to support these
features.

@JukkaL JukkaL requested a review from ilevkivskyi April 4, 2018 14:45
Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

Looks good! I think we should merge this soon to avoid conflicts, so I am going to do this now.

@@ -277,6 +273,10 @@ def visit_file(self, file_node: MypyFile, fnam: str, options: Options,
self.is_typeshed_stub_file = self.errors.is_typeshed_file(file_node.path)
self.globals = file_node.names
self.patches = patches
self.named_tuple_analyzer = NamedTupleAnalyzer(options, self)
Copy link
Member

Choose a reason for hiding this comment

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

There is a bit strange asymmetry between NamedTupleAnanlyzer and TypedDictAnalyzer, because only the latter needs self.msg. It is needed by check_for_explicit_any, and it is a bit surprising that it doesn't appear in NamedTupleAnalyzer. I think it would be good or explain this asymmetry.

@@ -1794,11 +1603,11 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
for lvalue in s.lvalues:
self.store_declared_types(lvalue, s.type)
self.check_and_set_up_type_alias(s)
self.process_newtype_declaration(s)
self.newtype_analyzer.process_newtype_declaration(s)
Copy link
Member

Choose a reason for hiding this comment

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

Rather a comment for myself: NewType and TypeVar not requiring self.is_func_scope() are by interesting coincidence(?) behave in weird way with forward references in fine grained, see e.g. #4615

@ilevkivskyi ilevkivskyi merged commit 634316c into master Apr 4, 2018
@ilevkivskyi ilevkivskyi deleted the refactor-namedtuple branch April 4, 2018 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants