Skip to content

update two classes to use StrEnum as their base class, when available. #11100

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 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions stdlib/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,12 @@ class DataclassInstance(Protocol):
# Anything that can be passed to the int/float constructors
ConvertibleToInt: TypeAlias = str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc
ConvertibleToFloat: TypeAlias = str | ReadableBuffer | SupportsFloat | SupportsIndex

# A few classes updated from Foo(str, Enum) to Foo(StrEnum). This is a convenience so these
# can be accurate on all python versions without getting too wordy
if sys.version_info >= (3, 11):
from enum import StrEnum as StrEnum
else:
from enum import Enum

class StrEnum(str, Enum): ...
5 changes: 2 additions & 3 deletions stdlib/pstats.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import sys
from _typeshed import StrOrBytesPath
from _typeshed import StrEnum, StrOrBytesPath
from collections.abc import Iterable
from cProfile import Profile as _cProfile
from enum import Enum
from profile import Profile
from typing import IO, Any, overload
from typing_extensions import Literal, Self, TypeAlias
Expand All @@ -14,7 +13,7 @@ else:

_Selector: TypeAlias = str | float | int

class SortKey(str, Enum):
class SortKey(StrEnum):
CALLS: str
CUMULATIVE: str
FILENAME: str
Expand Down
5 changes: 2 additions & 3 deletions stdlib/tkinter/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import _tkinter
import sys
from _typeshed import Incomplete, StrOrBytesPath
from _typeshed import Incomplete, StrEnum, StrOrBytesPath
from collections.abc import Callable, Mapping, Sequence
from enum import Enum
from tkinter.constants import *
from tkinter.font import _FontDescription
from types import TracebackType
Expand Down Expand Up @@ -195,7 +194,7 @@ if sys.version_info >= (3, 11):
releaselevel: str
serial: int

class EventType(str, Enum):
class EventType(StrEnum):
Activate: str
ButtonPress: str
Button = ButtonPress
Expand Down
4 changes: 4 additions & 0 deletions tests/stubtest_allowlists/py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,7 @@ pkgutil.ImpImporter\..*
pkgutil.ImpLoader\..*

types.CodeType.replace # stubtest thinks default values are None but None doesn't work at runtime

# These enums derive from (str, Enum)
pstats.SortKey.__new__
tkinter.EventType.__new__
4 changes: 4 additions & 0 deletions tests/stubtest_allowlists/py38.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,7 @@ tkinter.test
tkinter\.test\..+
unittest.test
unittest\.test\..+

# These enums derive from (str, Enum)
pstats.SortKey.__new__
tkinter.EventType.__new__
4 changes: 4 additions & 0 deletions tests/stubtest_allowlists/py39.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,7 @@ pkgutil.ImpImporter\..*
pkgutil.ImpLoader\..*

types.CodeType.replace # stubtest thinks default values are None but None doesn't work at runtime

# These enums derive from (str, Enum)
pstats.SortKey.__new__
tkinter.EventType.__new__
4 changes: 0 additions & 4 deletions tests/stubtest_allowlists/py3_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,6 @@ inspect.Signature.__init__
inspect.Parameter.empty # set as private marker _empty
inspect.Signature.empty # set as private marker _empty

# These enums derive from (int, IntEnum) or (str, Enum)
pstats.SortKey.__new__
tkinter.EventType.__new__

# These multiprocessing proxy methods have *args, **kwargs signatures at runtime,
# But have more precise (accurate) signatures in the stub
multiprocessing.managers.BaseListProxy.__imul__
Expand Down