Skip to content
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

enum: update for py310 #5314

Merged
merged 1 commit into from
May 4, 2021
Merged
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
20 changes: 19 additions & 1 deletion stdlib/enum.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from abc import ABCMeta
from builtins import property as _builtins_property
from typing import Any, Dict, Iterator, List, Mapping, Type, TypeVar, Union

_T = TypeVar("_T")
Expand All @@ -15,7 +16,7 @@ class EnumMeta(ABCMeta):
def __reversed__(self: Type[_T]) -> Iterator[_T]: ...
def __contains__(self: Type[Any], member: object) -> bool: ...
def __getitem__(self: Type[_T], name: str) -> _T: ...
@property
@_builtins_property
def __members__(self: Type[_T]) -> Mapping[str, _T]: ...
def __len__(self) -> int: ...

Expand Down Expand Up @@ -74,3 +75,20 @@ class IntFlag(int, Flag):
__ror__ = __or__
__rand__ = __and__
__rxor__ = __xor__

if sys.version_info >= (3, 10):
class StrEnum(str, Enum):
def __new__(cls: Type[_T], value: Union[int, _T]) -> _T: ...
class FlagBoundary(StrEnum):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used anywhere. Is there no way to say "class Foo(Flag, boundary=...) takes a boundary argument of this type?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think so: python/mypy#2653. Perhaps we can add a stub for __init_subclass__ or __new__ or whatever black magic enum is doing to implement this.

STRICT: str
CONFORM: str
EJECT: str
KEEP: str
STRICT = FlagBoundary.STRICT
CONFORM = FlagBoundary.CONFORM
EJECT = FlagBoundary.EJECT
KEEP = FlagBoundary.KEEP
class property(_builtins_property): ...
def global_enum(cls: _S) -> _S: ...
def global_enum_repr(self: Enum) -> str: ...
def global_flag_repr(self: Flag) -> str: ...