-
-
Notifications
You must be signed in to change notification settings - Fork 278
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
Infer user-defined enum classes by checking if the class is a subtype of enum.Enum
#2277
Infer user-defined enum classes by checking if the class is a subtype of enum.Enum
#2277
Conversation
return any( | ||
klass.name in ENUM_BASE_NAMES | ||
and getattr(klass.root(), "name", None) == "enum" | ||
for klass in cls.mro() |
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.
cls.mro()
wasn't returning the enum
ancestors in the case of the example on the original issue; hence the class never made became inferred. (it only returned a single-item list containing the original class itself).
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 like a slight performance improvement, too, based on the small sample size of profiling astroid.
bed2f14
to
7c44571
Compare
… of ``enum.Enum``. Closes pylint-dev/pylint#8897
7c44571
to
2bb499d
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.
On top of the fix, it seems like a more sensible approach indeed, good job. Did we have tests for each hard coded subclasses from the removed constants ? (I want to make sure that intEnum are still handled correctly)
Yes for IntEnum. |
Sorry if this test will be difficult to rewrite! Maybe an extra inference call in the setup? |
@jacobtylerwalls I've tried a few things to modify the test but no luck; when the program enters the enum brain module and into the |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #2277 +/- ##
==========================================
- Coverage 92.85% 92.85% -0.01%
==========================================
Files 94 94
Lines 11058 11054 -4
==========================================
- Hits 10268 10264 -4
Misses 790 790
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Type of Changes
Description
Infer user-defined enum classes by checking if the class is a subtype of
enum.Enum
.Closes pylint-dev/pylint#8897