diff --git a/stdlib/enum.pyi b/stdlib/enum.pyi index 9ebeba37ab71..37d90443ef68 100644 --- a/stdlib/enum.pyi +++ b/stdlib/enum.pyi @@ -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): diff --git a/tests/stubtest_allowlists/py311.txt b/tests/stubtest_allowlists/py311.txt index 72919d32c1e2..c02a30f5c5b7 100644 --- a/tests/stubtest_allowlists/py311.txt +++ b/tests/stubtest_allowlists/py311.txt @@ -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