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 analyser: Fix Any kinds for special forms #7148

Merged
merged 1 commit into from
Jul 4, 2019

Conversation

ilevkivskyi
Copy link
Member

Fixes #7118

Previously left hand sides of special forms were inferred as TypeOfAny.from_error. Note that total number of expressions in one of the tests is now smaller because of the subtle logic in visiting definitions of special forms, but I don't think it is import to keep it one-to-one with old analyser.

@ilevkivskyi ilevkivskyi requested a review from JukkaL July 4, 2019 15:02
Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Looks reasonable, but I'm still not sure why this was broken.

@@ -156,6 +156,11 @@ def visit_name_expr(self, e: NameExpr) -> Type:
def analyze_ref_expr(self, e: RefExpr, lvalue: bool = False) -> Type:
result = None # type: Optional[Type]
node = e.node

if isinstance(e, NameExpr) and e.is_special_form:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you know how did this work with the old semantic analyzer (i.e. why do we need this now)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this is again the story from #6458. Old analyzer generates a spurious Var as an lvalue node for special form assignments, and thus the type of lvalue is actually inferred (but still Any because this is what rvalue returns). The new analyzer doesn't do this, so that we fall through to the end in the if just below, thus getting TypeOfAny.from_error.

@ilevkivskyi ilevkivskyi merged commit bc34653 into python:master Jul 4, 2019
@ilevkivskyi ilevkivskyi deleted the newan-fix-any-kinds branch July 4, 2019 17:20
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.

Couple report tests show deviation on new analyzer
2 participants