Add EnumMeta.__bool__ (#7206)

Most Python objects evaluate as falsey if they have length 0, but an enum class is truthy even if it has length 0.

Source code: 841c77d802/Lib/enum.py (L353)
This commit is contained in:
Alex Waygood
2022-02-14 21:03:17 +00:00
committed by GitHub
parent f03d385012
commit 5972da2e2d

View File

@@ -5,6 +5,7 @@ from abc import ABCMeta
from builtins import property as _builtins_property
from collections.abc import Iterable, Iterator, Mapping
from typing import Any, TypeVar, Union, overload
from typing_extensions import Literal
_T = TypeVar("_T")
_S = TypeVar("_S", bound=type[Enum])
@@ -54,6 +55,7 @@ class EnumMeta(ABCMeta):
@_builtins_property
def __members__(self: type[_T]) -> types.MappingProxyType[str, _T]: ...
def __len__(self) -> int: ...
def __bool__(self) -> Literal[True]: ...
if sys.version_info >= (3, 11):
# Simple value lookup
@overload # type: ignore[override]