enum: More changes for 3.11 (#7862)

This commit is contained in:
Alex Waygood
2022-05-19 03:35:22 +01:00
committed by GitHub
parent 9a09db46f5
commit 04dde4d000
2 changed files with 22 additions and 12 deletions

View File

@@ -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
@@ -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
@@ -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):