-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
Fix inference cycle in getattr when a base is an astroid.Attribute #934
Fix inference cycle in getattr when a base is an astroid.Attribute #934
Conversation
eb2e14d
to
fdf69e0
Compare
fdf69e0
to
e402894
Compare
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.
Ref pylint-dev#904. `getattr` attempts to find values on `self.ancestors`, which infers each node listed in `self.bases`. Removing or resetting the context passed to ancestors allows it to infer the nodes, but opens up the possibility of cycles through recursive definitions. We should be able to infer the value of the base node correctly as a `ClassDef`. The root of this issue stems from the fact that `infer_attribute` attempts to temporarily set `context.boundnode`, but when unwrapping its changes it sets the `boundnode` to `None` instead of its previous value, which loses state and causes the inference of the `Attribute` node to have a duplicate key: once when looking up the class definition (which should have `boundnode = None`), and once when inferring the (other) attribute value (which should not have `boundnode = None`)
e402894
to
fa3731b
Compare
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 we should test these MR against pylint master?
@hippo91 I did some tests and didn't notice anything out of the ordinary. Good to merge once the discussions are resolved.
Steps
Description
Ref #904.
getattr
attempts to find values onself.ancestors
, whichinfers each node listed in
self.bases
. Removing or resetting thecontext passed to ancestors allows it to infer the nodes, but opens up
the possibility of cycles through recursive definitions. We should be
able to infer the value of the base node correctly as a
ClassDef
. Theroot of this issue stems from the fact that
infer_attribute
attemptsto temporarily set
context.boundnode
, but when unwrapping its changesit sets the
boundnode
toNone
instead of its previous value, whichloses state and causes the inference of the
Attribute
node to have aduplicate key: once when looking up the class definition (which should
have
boundnode = None
), and once when inferring the (other) attributevalue (which should not have
boundnode = None
)Type of Changes
Related Issue
Closes #904