Skip to content

Commit a8051fb

Browse files
Add _generate_next_value_ to StrEnum (#10390)
Fixes #10384 Co-authored-by: Alex Waygood <[email protected]>
1 parent 39fd112 commit a8051fb

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

stdlib/enum.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ if sys.version_info >= (3, 11):
237237
_value_: str
238238
@_magic_enum_attr
239239
def value(self) -> str: ...
240+
@staticmethod
241+
def _generate_next_value_(name: str, start: int, count: int, last_values: list[str]) -> str: ...
240242

241243
class EnumCheck(StrEnum):
242244
CONTINUOUS: str

test_cases/stdlib/check_enum.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from __future__ import annotations
2+
3+
import enum
4+
import sys
5+
from typing_extensions import Literal, assert_type
6+
7+
if sys.version_info >= (3, 11):
8+
9+
class Foo(enum.StrEnum):
10+
X = enum.auto()
11+
12+
assert_type(Foo.X, Literal[Foo.X])
13+
assert_type(Foo.X.value, str)

tests/stubtest_allowlists/py311.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ configparser.LegacyInterpolation.__init__
1717
configparser.ParsingError.filename
1818
enum.Enum.__init__
1919
enum.Enum._generate_next_value_
20+
# Not strictly speaking a staticmethod on 3.11, but it acts like one:
21+
enum.StrEnum._generate_next_value_
2022
importlib.abc.Finder.find_module
2123
ipaddress._BaseNetwork.broadcast_address
2224
ipaddress._BaseNetwork.hostmask

0 commit comments

Comments
 (0)