Skip to content

enum: More changes for 3.11 #7862

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
May 19, 2022
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
24 changes: 20 additions & 4 deletions stdlib/enum.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import types
from _typeshed import Self
from _typeshed import Self, SupportsKeysAndGetItem
from abc import ABCMeta
from builtins import property as _builtins_property
from collections.abc import Iterable, Iterator, Mapping
Expand Down Expand Up @@ -68,6 +68,16 @@ if sys.version_info >= (3, 11):
class _EnumDict(dict[str, Any]):
def __init__(self) -> None: ...
def __setitem__(self, key: str, value: Any) -> None: ...
if sys.version_info >= (3, 11):
# See comment above `typing.MutableMapping.update`
# for why overloads are preferable to a Union here
#
# Unlike with MutableMapping.update(), the first argument is required,
# hence the type: ignore
@overload # type: ignore[override]
def update(self, members: SupportsKeysAndGetItem[str, Any], **more_members: Any) -> None: ...
@overload
def update(self, members: Iterable[tuple[str, Any]], **more_members: Any) -> None: ...

# Note: EnumMeta actually subclasses type directly, not ABCMeta.
# This is a temporary workaround to allow multiple creation of enums with builtins
Expand Down Expand Up @@ -213,15 +223,21 @@ class Flag(Enum):
def __and__(self: Self, other: Self) -> Self: ...
def __xor__(self: Self, other: Self) -> Self: ...
def __invert__(self: Self) -> Self: ...
if sys.version_info >= (3, 11):
def __iter__(self: Self) -> Iterator[Self]: ...
def __len__(self) -> int: ...
__ror__ = __or__
__rand__ = __and__
__rxor__ = __xor__

class IntFlag(int, Flag):
def __new__(cls: type[Self], value: int) -> Self: ...
def __or__(self: Self, other: int) -> Self: ...
def __and__(self: Self, other: int) -> Self: ...
def __xor__(self: Self, other: int) -> Self: ...
def __ror__(self: Self, other: int) -> Self: ...
def __rand__(self: Self, other: int) -> Self: ...
def __rxor__(self: Self, other: int) -> Self: ...
__ror__ = __or__
__rand__ = __and__
__rxor__ = __xor__

if sys.version_info >= (3, 11):
class StrEnum(str, ReprEnum):
Expand Down
10 changes: 2 additions & 8 deletions tests/stubtest_allowlists/py311.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,14 @@ distutils.dist.DistributionMetadata.set_platforms
distutils.util.get_host_platform
enum.Enum.__init__
enum.Enum._generate_next_value_
enum.Flag.__iter__
enum.Flag.__len__
enum.Flag.__rand__
enum.Flag.__ror__
enum.Flag.__rxor__
enum.StrEnum.value
enum._EnumDict.update
enum.StrEnum.value # read-only property at runtime but too magical for stubtest
fractions.Fraction.__int__
fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve
ftplib.FTP.trust_server_pasv_ipv4_address
functools.partial.__vectorcalloffset__
gettext.install
hmac.new # Stub is a white lie; see comments in the stub
http.HTTPMethod.description
http.HTTPMethod.description # mutable instance attribute at runtime but we pretend it's a property
http.server.SimpleHTTPRequestHandler.__init__ # *args is expanded
imp.get_frozen_object
importlib.resources.Resource
Expand Down