From d7ee5eb41c7e7384dc6602985af05c0d5ba3d5d5 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 8 Jul 2019 11:19:04 +0300 Subject: [PATCH 1/3] builtins: int.__pow__ can take a modulo argument See: https://docs.python.org/3/reference/datamodel.html#object.__pow__ https://docs.python.org/3/library/functions.html#pow --- stdlib/2/__builtin__.pyi | 2 +- stdlib/2and3/builtins.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 6bc892f47ba7..4ee3d657673c 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -168,7 +168,7 @@ class int: def __rtruediv__(self, x: int) -> float: ... def __rmod__(self, x: int) -> int: ... def __rdivmod__(self, x: int) -> Tuple[int, int]: ... - def __pow__(self, x: int) -> Any: ... # Return type can be int or float, depending on x. + def __pow__(self, x: int, modulo: Optional[int] = ...) -> Any: ... # Return type can be int or float, depending on x. def __rpow__(self, x: int) -> Any: ... def __and__(self, n: int) -> int: ... def __or__(self, n: int) -> int: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 6bc892f47ba7..4ee3d657673c 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -168,7 +168,7 @@ class int: def __rtruediv__(self, x: int) -> float: ... def __rmod__(self, x: int) -> int: ... def __rdivmod__(self, x: int) -> Tuple[int, int]: ... - def __pow__(self, x: int) -> Any: ... # Return type can be int or float, depending on x. + def __pow__(self, x: int, modulo: Optional[int] = ...) -> Any: ... # Return type can be int or float, depending on x. def __rpow__(self, x: int) -> Any: ... def __and__(self, n: int) -> int: ... def __or__(self, n: int) -> int: ... From 3dd650922e3fda13347ca46418a4663132c4bea7 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 8 Jul 2019 11:07:57 +0300 Subject: [PATCH 2/3] builtins: add __ceil__, __floor__, __trunc__ to int and float on Python3 See: https://docs.python.org/3/reference/datamodel.html#object.__round__ --- stdlib/2/__builtin__.pyi | 6 ++++++ stdlib/2and3/builtins.pyi | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 4ee3d657673c..44ef2b6246d8 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -185,6 +185,9 @@ class int: def __invert__(self) -> int: ... if sys.version_info >= (3,): def __round__(self, ndigits: Optional[int] = ...) -> int: ... + def __trunc__(self) -> int: ... + def __floor__(self) -> int: ... + def __ceil__(self) -> int: ... def __getnewargs__(self) -> Tuple[int]: ... def __eq__(self, x: object) -> bool: ... @@ -247,6 +250,9 @@ class float: def __round__(self, ndigits: None) -> int: ... @overload def __round__(self, ndigits: int) -> float: ... + def __trunc__(self) -> int: ... + def __floor__(self) -> int: ... + def __ceil__(self) -> int: ... def __eq__(self, x: object) -> bool: ... def __ne__(self, x: object) -> bool: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 4ee3d657673c..44ef2b6246d8 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -185,6 +185,9 @@ class int: def __invert__(self) -> int: ... if sys.version_info >= (3,): def __round__(self, ndigits: Optional[int] = ...) -> int: ... + def __trunc__(self) -> int: ... + def __floor__(self) -> int: ... + def __ceil__(self) -> int: ... def __getnewargs__(self) -> Tuple[int]: ... def __eq__(self, x: object) -> bool: ... @@ -247,6 +250,9 @@ class float: def __round__(self, ndigits: None) -> int: ... @overload def __round__(self, ndigits: int) -> float: ... + def __trunc__(self) -> int: ... + def __floor__(self) -> int: ... + def __ceil__(self) -> int: ... def __eq__(self, x: object) -> bool: ... def __ne__(self, x: object) -> bool: ... From 919609d21bacb0d6b322b68b23c40cf1c9855995 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 8 Jul 2019 11:28:23 +0300 Subject: [PATCH 3/3] builtins,numbers: harmonize float.__round__ and Real.__round__ See: https://docs.python.org/3/reference/datamodel.html#object.__round__ https://docs.python.org/3/library/functions.html#round --- stdlib/2/__builtin__.pyi | 4 +--- stdlib/2and3/builtins.pyi | 4 +--- stdlib/2and3/numbers.pyi | 8 ++++++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 44ef2b6246d8..9563c32f1b78 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -245,9 +245,7 @@ class float: def __getnewargs__(self) -> Tuple[float]: ... if sys.version_info >= (3,): @overload - def __round__(self) -> int: ... - @overload - def __round__(self, ndigits: None) -> int: ... + def __round__(self, ndigits: None = ...) -> int: ... @overload def __round__(self, ndigits: int) -> float: ... def __trunc__(self) -> int: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 44ef2b6246d8..9563c32f1b78 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -245,9 +245,7 @@ class float: def __getnewargs__(self) -> Tuple[float]: ... if sys.version_info >= (3,): @overload - def __round__(self) -> int: ... - @overload - def __round__(self, ndigits: None) -> int: ... + def __round__(self, ndigits: None = ...) -> int: ... @overload def __round__(self, ndigits: int) -> float: ... def __trunc__(self) -> int: ... diff --git a/stdlib/2and3/numbers.pyi b/stdlib/2and3/numbers.pyi index 50b561c24a32..befe7d53a781 100644 --- a/stdlib/2and3/numbers.pyi +++ b/stdlib/2and3/numbers.pyi @@ -5,7 +5,7 @@ # Note: these stubs are incomplete. The more complex type # signatures are currently omitted. -from typing import Any, Optional, SupportsFloat +from typing import Any, Optional, SupportsFloat, overload from abc import ABCMeta, abstractmethod import sys @@ -70,7 +70,11 @@ class Real(Complex, SupportsFloat): @abstractmethod def __ceil__(self) -> int: ... @abstractmethod - def __round__(self, ndigits: Optional[int] = ...): ... + @overload + def __round__(self, ndigits: None = ...): ... + @abstractmethod + @overload + def __round__(self, ndigits: int): ... def __divmod__(self, other): ... def __rdivmod__(self, other): ... @abstractmethod