Fix recently added enum value type prediction #10057
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In #9443, some code was added to predict the type of enum values where it is not explicitly when all enum members have the same type.
However, it didn't consider that subclasses of Enum that have a custom
__new__
implementation may use any type for the enum value (typically it would use only one of their parameters instead of a whole tuple that is specified in the definition of the member). Fix this by avoiding to guess the enum value type in classes that implement__new__
.In addition, the added code was buggy in that it didn't only consider class attributes as enum members, but also instance attributes assigned to self.* in
__init__
. Fix this by ignoring implicit nodes when checking the enum members.Fixes #10000.
Test Plan
Apart from manually testing the example from #10000, new unit tests are included for the changed behaviour that fail on master (when running
runtests.py
) and pass with this fix applied. Unchanged behaviour is already tested by existing unit tests.