Skip to content

Experiment: remove IntFlag from enum.auto #12760

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 4 commits into from
Oct 9, 2024
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
5 changes: 5 additions & 0 deletions stdlib/@tests/stubtest_allowlists/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -670,3 +670,8 @@ typing(_extensions)?\.IO\.__iter__ # See https://github.com/python/typeshed/com
(xml.etree.cElementTree.XMLPullParser.flush)?
(xml.parsers.expat.XMLParserType.GetReparseDeferralEnabled)?
(xml.parsers.expat.XMLParserType.SetReparseDeferralEnabled)?

# enum.auto is magic, see comments
enum.auto.__or__
enum.auto.__and__
enum.auto.__xor__
15 changes: 13 additions & 2 deletions stdlib/enum.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,24 @@ else:
__rand__ = __and__
__rxor__ = __xor__

# subclassing IntFlag so it picks up all implemented base functions, best modeling behavior of enum.auto()
class auto(IntFlag):
class auto:
_value_: Any
@_magic_enum_attr
def value(self) -> Any: ...
def __new__(cls) -> Self: ...

# These don't exist, but auto is basically immediately replaced with
# either an int or a str depending on the type of the enum. StrEnum's auto
# shouldn't have these, but they're needed for int versions of auto (mostly the __or__).
# Ideally type checkers would special case auto enough to handle this,
# but until then this is a slightly inaccurate helping hand.
def __or__(self, other: int | Self) -> Self: ...
def __and__(self, other: int | Self) -> Self: ...
def __xor__(self, other: int | Self) -> Self: ...
__ror__ = __or__
__rand__ = __and__
__rxor__ = __xor__

if sys.version_info >= (3, 11):
def pickle_by_global_name(self: Enum, proto: int) -> str: ...
def pickle_by_enum_name(self: _EnumMemberT, proto: int) -> tuple[Callable[..., Any], tuple[type[_EnumMemberT], str]]: ...
Loading