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

New semantic analyzer: generalize placeholders to all symbol nodes #6336

Merged
merged 16 commits into from
Feb 5, 2019

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Feb 5, 2019

This generalizes the concept of placeholder nodes to also cover
assignment statements and imports. Previously they were only
created for class definitions. The main motivation is to prevent
access to definitions in outer namespaces if there is an
incomplete definition that should take precedence.

Fixes #6299.

This also does a few other updates:

  • During the final iteration, some references to placeholder nodes
    generate an error instead of producing placeholder nodes. This
    allows the analysis to terminate in certain cases of import
    cycles at least.
  • Major refactoring of analyze_name_lvalue. The motivation is
    that some early experiments made the old structure unwieldy,
    but the refactoring may not be as important for the final design.
    This seems like a code quality improvement so I'm including it
    here.
  • If a name lvalue was bound during an earlier iteration, we don't
    rebind it. I'd like to gradually move to this approach more
    generally.
  • Some forward references to names aren't treated as undefined
    any more. I think that these worked by accident. Now these
    generally generate "cannot determine type" errors.
  • Most definitions won't generate incomplete namespaces any
    more, since placeholders count as definitions in this context.
    Star imports still generate incomplete namespaces.
  • Remove redundant flags from some test cases.

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 very good! I just have one question.

if self.is_alias_for_final_name(lval.name):
if lvalue.node:
# This has been bound already in a previous iteration.
return
Copy link
Member

Choose a reason for hiding this comment

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

Why do we do this for names but not for attributes? Maybe leave a comment/TODO about this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll create an issue about dealing with attribute definitions (through self.x).

@JukkaL JukkaL merged commit 15e9b5b into master Feb 5, 2019
@gvanrossum gvanrossum deleted the semanal-placeholder branch February 5, 2019 21:49
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