From 3faf17cca816d07d95507c2da93e4a5cda5f2b74 Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Wed, 21 Aug 2024 18:38:31 +0200 Subject: [PATCH] added __bool__ to object. --- stdlib/_typeshed/__init__.pyi | 3 +++ stdlib/builtins.pyi | 1 + 2 files changed, 4 insertions(+) diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index ace3094199a9..f85f85ab781c 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -71,6 +71,9 @@ MaybeNone: TypeAlias = Any # stable sentinel: Any class SupportsBool(Protocol): + # NOTE: Since object is a subtype of SupportsBool, this protocol is redundant. + # However, it is kept for clarity, as comparisons are generally expected + # to return boolean-like values. def __bool__(self) -> bool: ... # stable diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 95335d241ea1..4a24d8f39226 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -105,6 +105,7 @@ class object: def __class__(self, type: type[object], /) -> None: ... def __init__(self) -> None: ... def __new__(cls) -> Self: ... + def __bool__(self) -> bool: ... # N.B. `object.__setattr__` and `object.__delattr__` are heavily special-cased by type checkers. # Overriding them in subclasses has different semantics, even if the override has an identical signature. def __setattr__(self, name: str, value: Any, /) -> None: ...