Skip to content

New analyser: fix crashes when plugins encounter a placeholder node #7132

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 5 commits into from
Jul 2, 2019

Conversation

ilevkivskyi
Copy link
Member

Fixes #7098

@ilevkivskyi ilevkivskyi requested a review from JukkaL July 2, 2019 15:42
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 good, just a few minor comments.

@@ -270,7 +270,9 @@ def _analyze_class(ctx: 'mypy.plugin.ClassDefContext',
# instance level assignments.
if attribute.name in ctx.cls.info.names:
node = ctx.cls.info.names[attribute.name].node
assert isinstance(node, Var)
if not isinstance(node, Var):
# This node may be not ready yet (i.e. a PlaceholderNode).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we instead check for PlaceholderNode? If there's something unexpected there, weird things might happen.

total = attr.ib(type=Bad) # E: Name 'Bad' is not defined
[builtins fixtures/bool.pyi]

[case testTypeInAttrBad2]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe rename the test case? There seems nothing bad here, just a forward reference.

class Forward: ...
[builtins fixtures/bool.pyi]

[case testTypeInAttrBad3]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar to above, the test case name doesn't seem quite right.

@ilevkivskyi
Copy link
Member Author

Travis looks stuck. I am going to merge this now.

@ilevkivskyi ilevkivskyi merged commit d8cde02 into python:master Jul 2, 2019
@ilevkivskyi ilevkivskyi deleted the fix-attrs-newan branch July 2, 2019 18:55
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.

New analyser: Crash in attrs plugin on bad or deferred name
2 participants