From dfe4a577e39493e196bd913bf627359a5eaec136 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 14 Feb 2022 19:16:05 +0000 Subject: [PATCH] Add `EnumMeta.__bool__` 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 --- stdlib/enum.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stdlib/enum.pyi b/stdlib/enum.pyi index 72ea42f368e6..437c2ebdc7b6 100644 --- a/stdlib/enum.pyi +++ b/stdlib/enum.pyi @@ -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]