-
-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve inference of Enum members called "name" and "value" (#1020)
* Add DynamicClassAttribute to list of properties 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. * Add fake "name" property to enum.Enum subclasses 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. Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
- Loading branch information
1 parent
032fb3a
commit 4c9b9b5
Showing
4 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,7 @@ | |
"LazyProperty", | ||
"lazy", | ||
"cache_readonly", | ||
"DynamicClassAttribute", | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters