Skip to content

Commit 5972da2

Browse files
authored
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: https://github.com/python/cpython/blob/841c77d802e9ee8845fa3152700474021efe03fd/Lib/enum.py#L353
1 parent f03d385 commit 5972da2

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

stdlib/enum.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ from abc import ABCMeta
55
from builtins import property as _builtins_property
66
from collections.abc import Iterable, Iterator, Mapping
77
from typing import Any, TypeVar, Union, overload
8+
from typing_extensions import Literal
89

910
_T = TypeVar("_T")
1011
_S = TypeVar("_S", bound=type[Enum])
@@ -54,6 +55,7 @@ class EnumMeta(ABCMeta):
5455
@_builtins_property
5556
def __members__(self: type[_T]) -> types.MappingProxyType[str, _T]: ...
5657
def __len__(self) -> int: ...
58+
def __bool__(self) -> Literal[True]: ...
5759
if sys.version_info >= (3, 11):
5860
# Simple value lookup
5961
@overload # type: ignore[override]

0 commit comments

Comments
 (0)