Skip to content

New semantic analyzer: don't add submodules to symbol tables - #7005

Merged
JukkaL merged 16 commits into
masterfrom
semanal-refactor-submodules
Jun 17, 2019
Merged

JukkaL merged 16 commits into
masterfrom
semanal-refactor-submodules

Conversation

@JukkaL

@JukkaL JukkaL commented Jun 17, 2019

Copy link
Copy Markdown
Collaborator

Previously we added each submodule implicitly to the the symbol table of
the parent package. This PR removes this and instead we look up names from
the modules dictionary if they aren't found in the symbol table. The change
only affects the new semantic analyzer.

This provides the foundation that should make it easier to fix #6828. It also
arguably cleans up the code.

Also refactor some related code to avoid duplication.

This isn't a pure refactor since some error messages are slightly different.

@JukkaL
JukkaL requested a review from ilevkivskyi June 17, 2019 15:02

@ilevkivskyi ilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the cleanup, looks good! I have couple requests for tests/comments.

Also edit the PR description before merging otherwise this will close #6828.

Comment thread mypy/newsemanal/semanal.py Outdated
else:
if self.is_incomplete_namespace(file.fullname()):
self.record_incomplete_ref()
# Handle 'module.foo'.

@ilevkivskyi ilevkivskyi Jun 17, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doesn't this comment just duplicate the one two lines above?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed one of the comments.

Comment thread mypy/newsemanal/semanal.py Outdated
# Rebind potential references to old version of current module in
# fine-grained incremental mode.
if module == self.cur_mod_id:
names = self.globals

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since we are here again, could you please add a test that would fail without these two lines. Currently all tests pass if I remove them.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I couldn't come up with a test that would require this. It's possible that fine-grained dependencies will deal with all the cases that this was supposed to handle. I've removed this now.

var_type = AnyType(TypeOfAny.from_unimported_type)
v = Var(name, type=var_type)
v._fullname = fullname
sym = SymbolTableNode(GDEF, v)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe add a comment explaining why we create a new Var every time for technically the same missing module? (IIUC the logic is the same as explained in the docstring for create_getattr_var()).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added a comment.

@JukkaL
JukkaL merged commit 9eb2468 into master Jun 17, 2019
@gvanrossum
gvanrossum deleted the semanal-refactor-submodules branch June 17, 2019 18:33
PattenR pushed a commit to PattenR/mypy that referenced this pull request Jun 23, 2019
…7005)

Previously we added each submodule implicitly to the the symbol table of
the parent package. This PR removes this and instead we look up names from
the modules dictionary if they aren't found in the symbol table. The change
only affects the new semantic analyzer.

This provides a foundation that should make python#6828 much easier to address. It 
also arguably cleans up the code.

Also refactor some related code to avoid duplication.

This isn't a pure refactor since some error messages are slightly different.
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.

Uncertainty between submodule and local definition in new semantic analyzer

2 participants