-
-
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
Improve inference of Enum members called "name" and "value" #1020
Improve inference of Enum members called "name" and "value" #1020
Conversation
DynamicClassAttribute is a descriptor defined in Python's Lib/types.py which changes the behaviour of an attribute depending on if it is looked up on the class or on an instance.
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.
The explanation in the comment is great, I needed that :)
Thanks. I was thinking that it'd probably need explaining, and instead of sticking it in the PR, I'll just stick it in a comment straight away. Re: the test failure on 3.10, it looks like the enum module has undergone a fairly extensive re-write. I'll update the tests since I don't think we really care what the value of the ".value" attribute is in a class context |
Ref pylint-dev/pylint#1932. Ref pylint-dev/pylint#2062. The enum.Enum class itself defines two @DynamicClassAttribute data-descriptors "name" and "value" which behave differently when looked up on an instance or on the class. When dealing with inference of an arbitrary instance of the enum class, e.g. in a method defined in the class body like: class SomeEnum(enum.Enum): def method(self): self.name # <- here we should assume that "self.name" is the string name of some enum member, unless the enum itself defines a "name" member.
fff5aa0
to
b39e76b
Compare
Improve inference of Enum members called "name" and "value"
Steps
Description
The attributes .name and .value on the enum.Enum are defined as data-descriptors (but not plain
@property
methods) that behave differently when the attribute access is on the class or an instance. This change updates the enum brain to provide better guesses for values (and appropriate changes if the enum happens to define a member named "name" or "value").Type of Changes
Related Issue
pylint-dev/pylint#1932
pylint-dev/pylint#2062