-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Conversation
There was a problem hiding this 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.
mypy/plugins/attrs.py
Outdated
@@ -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). |
There was a problem hiding this comment.
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.
test-data/unit/check-attr.test
Outdated
total = attr.ib(type=Bad) # E: Name 'Bad' is not defined | ||
[builtins fixtures/bool.pyi] | ||
|
||
[case testTypeInAttrBad2] |
There was a problem hiding this comment.
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.
test-data/unit/check-attr.test
Outdated
class Forward: ... | ||
[builtins fixtures/bool.pyi] | ||
|
||
[case testTypeInAttrBad3] |
There was a problem hiding this comment.
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.
Travis looks stuck. I am going to merge this now. |
Fixes #7098