Skip to content

Add _generate_next_value_ to StrEnum - #10390

Merged
AlexWaygood merged 6 commits into
mainfrom
sobolevn-patch-1
Jul 1, 2023
Merged

Add _generate_next_value_ to StrEnum#10390
AlexWaygood merged 6 commits into
mainfrom
sobolevn-patch-1

Conversation

@sobolevn

Copy link
Copy Markdown
Member

This change is enough to (at least partially) fix#10384

Why? Because mypy already had this plugin in place: https://github.com/python/mypy/blob/b995e1620789a3ab2fc5dbcf0698a9077b0f5731/mypy/plugins/enums.py#L85-L90

Source: https://github.com/python/cpython/blob/319de0b578ec3dec8d30610caee3aa93f51060c7/Lib/enum.py#L1279

So, adding it locally produces:

fromenumimportStrEnum, autoclassA(StrEnum):
a=auto()
reveal_type(type(A.a)) # N: Revealed type is "Type[Literal[ex.A.a]?]"reveal_type(type(A.a.value)) # N: Revealed type is "Type[builtins.str]"

Closes#10384

This change is enough to (at least partially) fix#10384
Why? Because `mypy` already had this plugin in place: https://github.com/python/mypy/blob/b995e1620789a3ab2fc5dbcf0698a9077b0f5731/mypy/plugins/enums.py#L85-L90
So, adding it locally produces:
```python
from enum import StrEnum, auto
class A(StrEnum):
a = auto()
reveal_type(type(A.a)) # N: Revealed type is "Type[Literal[ex.A.a]?]"
reveal_type(type(A.a.value)) # N: Revealed type is "Type[builtins.str]"
```
Closes#10384
@AlexWaygoodAlexWaygood changed the title Add _generate_next_value to StrEnumAdd _generate_next_value_ to StrEnumJun 30, 2023
Comment threadtests/stubtest_allowlists/py311.txt
Comment threadtests/stubtest_allowlists/py311.txt
Comment threadstdlib/enum.pyi Outdated
Comment threadtests/stubtest_allowlists/py311.txt Outdated
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>

@AlexWaygoodAlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@AlexWaygood
AlexWaygood merged commit a8051fb into mainJul 1, 2023
@AlexWaygood
AlexWaygood deleted the sobolevn-patch-1 branch July 1, 2023 17:28
Sign up for freeto 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.

auto for StrEnum is incorrectly subclassing IntFlag

3 participants

@sobolevn@JelleZijlstra@AlexWaygood