From 78b9dd01d1842ceffde5f0436f53dd29e13e3a0e Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Tue, 19 Apr 2022 17:26:25 +0100 Subject: [PATCH] Add back comments to `builtins` --- stdlib/builtins.pyi | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 431c880f07f0..bf1e6cde2c08 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -101,6 +101,8 @@ class object: def __format__(self, __format_spec: str) -> str: ... def __getattribute__(self, __name: str) -> Any: ... def __sizeof__(self) -> int: ... + # return type of pickle methods is rather hard to express in the current type system + # see #6661 and https://docs.python.org/3/library/pickle.html#object.__reduce__ def __reduce__(self) -> str | tuple[Any, ...]: ... if sys.version_info >= (3, 8): def __reduce_ex__(self, __protocol: SupportsIndex) -> str | tuple[Any, ...]: ... @@ -258,6 +260,8 @@ class int: def __pow__(self, __x: _PositiveInteger, __modulo: None = ...) -> int: ... @overload def __pow__(self, __x: _NegativeInteger, __modulo: None = ...) -> float: ... + # positive x -> int; negative x -> float + # return type must be Any as `int | float` causes too many false-positive errors @overload def __pow__(self, __x: int, __modulo: None = ...) -> Any: ... def __rpow__(self, __x: int, __mod: int | None = ...) -> Any: ... @@ -313,6 +317,8 @@ class float: def __divmod__(self, __x: float) -> tuple[float, float]: ... @overload def __pow__(self, __x: int, __mod: None = ...) -> float: ... + # positive x -> float; negative x -> complex + # return type must be Any as `float | complex` causes too many false-positive errors @overload def __pow__(self, __x: float, __mod: None = ...) -> Any: ... def __radd__(self, __x: float) -> float: ... @@ -322,6 +328,7 @@ class float: def __rtruediv__(self, __x: float) -> float: ... def __rmod__(self, __x: float) -> float: ... def __rdivmod__(self, __x: float) -> tuple[float, float]: ... + # Returns complex if the argument is negative. def __rpow__(self, __x: float, __mod: None = ...) -> Any: ... def __getnewargs__(self) -> tuple[float]: ... def __trunc__(self) -> int: ... @@ -1411,10 +1418,15 @@ if sys.version_info >= (3, 8): def pow(base: int, exp: _PositiveInteger, mod: None = ...) -> int: ... # type: ignore[misc] @overload def pow(base: int, exp: _NegativeInteger, mod: None = ...) -> float: ... # type: ignore[misc] + # int base & positive-int exp -> int; int base & negative-int exp -> float + # return type must be Any as `int | float` causes too many false-positive errors @overload def pow(base: int, exp: int, mod: None = ...) -> Any: ... @overload def pow(base: float, exp: int, mod: None = ...) -> float: ... + # float base & float exp could return float or complex + # return type must be Any (same as complex base, complex exp), + # as `float | complex` causes too many false-positive errors @overload def pow(base: float, exp: complex | _SupportsSomeKindOfPow, mod: None = ...) -> Any: ... @overload