Skip to content

Fix inference of IntEnum value attribute type #10412

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

Merged
merged 2 commits into from
May 4, 2021
Merged

Fix inference of IntEnum value attribute type #10412

merged 2 commits into from
May 4, 2021

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented May 4, 2021

If the enum value initializer has a NewType type, it should be
reflected in the type of the value attribute. It was broken because
the special casing for __new__ introduced in #10057 didn't consider
the __new__ in IntEnum as special.

Fixes #10411.

If the enum value initializer has a NewType type, it should be
reflected in the type of the `value` attribute. It was broken because
the special casing for `__new__` introduced in #10057 didn't consider
the `__new__` in `IntEnum` as special.

Fixes #10411.
Co-authored-by: Jelle Zijlstra <[email protected]>
@JukkaL JukkaL merged commit b17e33f into master May 4, 2021
@JukkaL JukkaL deleted the enum-newtype branch May 4, 2021 14:17
JukkaL added a commit that referenced this pull request May 4, 2021
The enum stubs for Python 2 are slightly different from Python 3.
The fix in #10412 didn't quite work in Python 2 mode, since `IntEnum`
doesn't define `__new__`, and the `__new__` from `builtins.int` is
found instead. Work around this by skipping any `__new__` methods
found in built-in types.

I gave up trying to write a test case for this. It's tricky because
`enum` is in Python 3 stdlib but not in Python 2 stdlib.
JukkaL added a commit that referenced this pull request May 4, 2021
The enum stubs for Python 2 are slightly different from Python 3.
The fix in #10412 didn't quite work in Python 2 mode, since `IntEnum`
doesn't define `__new__`, and the `__new__` from `builtins.int` is
found instead. Work around this by skipping any `__new__` methods
found in built-in types.

I gave up trying to write a test case for this. It's tricky because
`enum` is in Python 3 stdlib but not in Python 2 stdlib.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IntEnum with NewType value type regression
3 participants