From f37062ddc1291524f261a5399e7040679dcb1948 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Thu, 6 Aug 2020 16:58:03 -0700 Subject: [PATCH 01/14] Added missing type annotations for fractions and numbers modules. --- stdlib/2and3/fractions.pyi | 35 +++++++-------- stdlib/2and3/numbers.pyi | 89 +++++++++++++++++++------------------- 2 files changed, 62 insertions(+), 62 deletions(-) diff --git a/stdlib/2and3/fractions.pyi b/stdlib/2and3/fractions.pyi index 56df924472bf..c360ad001a00 100644 --- a/stdlib/2and3/fractions.pyi +++ b/stdlib/2and3/fractions.pyi @@ -39,25 +39,25 @@ class Fraction(Rational): def numerator(self) -> int: ... @property def denominator(self) -> int: ... - def __add__(self, other): ... - def __radd__(self, other): ... - def __sub__(self, other): ... - def __rsub__(self, other): ... - def __mul__(self, other): ... - def __rmul__(self, other): ... - def __truediv__(self, other): ... - def __rtruediv__(self, other): ... + def __add__(self, other: _ComparableNum) -> Fraction: ... + def __radd__(self, other: _ComparableNum) -> Fraction: ... + def __sub__(self, other: _ComparableNum) -> Fraction: ... + def __rsub__(self, other: _ComparableNum) -> Fraction: ... + def __mul__(self, other: _ComparableNum) -> Fraction: ... + def __rmul__(self, other: _ComparableNum) -> Fraction: ... + def __truediv__(self, other: _ComparableNum) -> Fraction: ... + def __rtruediv__(self, other: _ComparableNum) -> Fraction: ... if sys.version_info < (3, 0): def __div__(self, other): ... def __rdiv__(self, other): ... - def __floordiv__(self, other) -> int: ... - def __rfloordiv__(self, other) -> int: ... - def __mod__(self, other): ... - def __rmod__(self, other): ... - def __divmod__(self, other): ... - def __rdivmod__(self, other): ... - def __pow__(self, other): ... - def __rpow__(self, other): ... + def __floordiv__(self, other: _ComparableNum) -> int: ... + def __rfloordiv__(self, other: _ComparableNum) -> int: ... + def __mod__(self, other: _ComparableNum) -> Fraction: ... + def __rmod__(self, other: _ComparableNum) -> Fraction: ... + def __divmod__(self, other: _ComparableNum) -> Fraction: ... + def __rdivmod__(self, other: _ComparableNum) -> Fraction: ... + def __pow__(self, other: _ComparableNum) -> Fraction: ... + def __rpow__(self, other: _ComparableNum) -> Fraction: ... def __pos__(self) -> Fraction: ... def __neg__(self) -> Fraction: ... def __abs__(self) -> Fraction: ... @@ -65,7 +65,7 @@ class Fraction(Rational): if sys.version_info >= (3, 0): def __floor__(self) -> int: ... def __ceil__(self) -> int: ... - def __round__(self, ndigits: Optional[Any] = ...): ... + def __round__(self, ndigits: Optional[Any] = ...) -> Fraction: ... def __hash__(self) -> int: ... def __eq__(self, other: object) -> bool: ... def __lt__(self, other: _ComparableNum) -> bool: ... @@ -83,3 +83,4 @@ class Fraction(Rational): @property def imag(self) -> Fraction: ... def conjugate(self) -> Fraction: ... + diff --git a/stdlib/2and3/numbers.pyi b/stdlib/2and3/numbers.pyi index a010a4fa479e..a1ac1fef4c48 100644 --- a/stdlib/2and3/numbers.pyi +++ b/stdlib/2and3/numbers.pyi @@ -7,7 +7,9 @@ import sys from abc import ABCMeta, abstractmethod -from typing import Any, Optional, SupportsFloat, overload +from typing import Any, Optional, SupportsFloat, Type, TypeVar + +_T = TypeVar("_T") class Number(metaclass=ABCMeta): @abstractmethod @@ -22,39 +24,39 @@ class Complex(Number): def __nonzero__(self) -> bool: ... @property @abstractmethod - def real(self): ... + def real(self) -> float: ... @property @abstractmethod - def imag(self): ... + def imag(self) -> float: ... @abstractmethod - def __add__(self, other): ... + def __add__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __radd__(self, other): ... + def __radd__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __neg__(self): ... + def __neg__(self: Type[_T]) -> _T: ... @abstractmethod - def __pos__(self): ... - def __sub__(self, other): ... - def __rsub__(self, other): ... + def __pos__(self: Type[_T]) -> _T: ... + def __sub__(self: Type[_T], other: object) -> _T: ... + def __rsub__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __mul__(self, other): ... + def __mul__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __rmul__(self, other): ... + def __rmul__(self: Type[_T], other: object) -> _T: ... if sys.version_info < (3, 0): @abstractmethod def __div__(self, other): ... @abstractmethod def __rdiv__(self, other): ... @abstractmethod - def __truediv__(self, other): ... + def __truediv__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __rtruediv__(self, other): ... + def __rtruediv__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __pow__(self, exponent): ... + def __pow__(self: Type[_T], exponent: object) -> _T: ... @abstractmethod - def __rpow__(self, base): ... - def __abs__(self): ... - def conjugate(self): ... + def __rpow__(self: Type[_T], base: object) -> _T: ... + def __abs__(self: Type[_T]) -> _T: ... + def conjugate(self: Type[_T]) -> _T: ... def __eq__(self, other: object) -> bool: ... if sys.version_info < (3, 0): def __ne__(self, other: object) -> bool: ... @@ -70,31 +72,27 @@ class Real(Complex, SupportsFloat): @abstractmethod def __ceil__(self) -> int: ... @abstractmethod - @overload - def __round__(self, ndigits: None = ...): ... - @abstractmethod - @overload - def __round__(self, ndigits: int): ... - def __divmod__(self, other): ... - def __rdivmod__(self, other): ... + def __round__(self: Type[_T], ndigits: Optional[int] = ...) -> _T: ... + def __divmod__(self: Type[_T], other: object) -> _T: ... + def __rdivmod__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __floordiv__(self, other): ... + def __floordiv__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __rfloordiv__(self, other): ... + def __rfloordiv__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __mod__(self, other): ... + def __mod__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __rmod__(self, other): ... + def __rmod__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __lt__(self, other) -> bool: ... + def __lt__(self, other: object) -> bool: ... @abstractmethod - def __le__(self, other) -> bool: ... + def __le__(self, other: object) -> bool: ... def __complex__(self) -> complex: ... @property - def real(self): ... + def real(self) -> float: ... @property - def imag(self): ... - def conjugate(self): ... + def imag(self) -> float: ... + def conjugate(self: Type[_T]) -> _T: ... class Rational(Real): @property @@ -114,31 +112,32 @@ class Integral(Rational): def __long__(self) -> long: ... def __index__(self) -> int: ... @abstractmethod - def __pow__(self, exponent, modulus: Optional[Any] = ...): ... + def __pow__(self: Type[_T], exponent: object, modulus: Optional[Any] = ...) -> _T: ... @abstractmethod - def __lshift__(self, other): ... + def __lshift__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __rlshift__(self, other): ... + def __rlshift__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __rshift__(self, other): ... + def __rshift__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __rrshift__(self, other): ... + def __rrshift__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __and__(self, other): ... + def __and__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __rand__(self, other): ... + def __rand__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __xor__(self, other): ... + def __xor__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __rxor__(self, other): ... + def __rxor__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __or__(self, other): ... + def __or__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __ror__(self, other): ... + def __ror__(self: Type[_T], other: object) -> _T: ... @abstractmethod - def __invert__(self): ... + def __invert__(self: Type[_T]) -> _T: ... def __float__(self) -> float: ... @property def numerator(self) -> int: ... @property def denominator(self) -> int: ... + From a2c18e63a1db37cd117f692a7795b21413651f91 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Thu, 6 Aug 2020 17:04:13 -0700 Subject: [PATCH 02/14] Fixed bad annotation for self. --- stdlib/2and3/numbers.pyi | 68 ++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/stdlib/2and3/numbers.pyi b/stdlib/2and3/numbers.pyi index a1ac1fef4c48..03664dc8aaa8 100644 --- a/stdlib/2and3/numbers.pyi +++ b/stdlib/2and3/numbers.pyi @@ -29,34 +29,34 @@ class Complex(Number): @abstractmethod def imag(self) -> float: ... @abstractmethod - def __add__(self: Type[_T], other: object) -> _T: ... + def __add__(self: _T, other: object) -> _T: ... @abstractmethod - def __radd__(self: Type[_T], other: object) -> _T: ... + def __radd__(self: _T, other: object) -> _T: ... @abstractmethod - def __neg__(self: Type[_T]) -> _T: ... + def __neg__(self: _T) -> _T: ... @abstractmethod - def __pos__(self: Type[_T]) -> _T: ... - def __sub__(self: Type[_T], other: object) -> _T: ... - def __rsub__(self: Type[_T], other: object) -> _T: ... + def __pos__(self: _T) -> _T: ... + def __sub__(self: _T, other: object) -> _T: ... + def __rsub__(self: _T, other: object) -> _T: ... @abstractmethod - def __mul__(self: Type[_T], other: object) -> _T: ... + def __mul__(self: _T, other: object) -> _T: ... @abstractmethod - def __rmul__(self: Type[_T], other: object) -> _T: ... + def __rmul__(self: _T, other: object) -> _T: ... if sys.version_info < (3, 0): @abstractmethod def __div__(self, other): ... @abstractmethod def __rdiv__(self, other): ... @abstractmethod - def __truediv__(self: Type[_T], other: object) -> _T: ... + def __truediv__(self: _T, other: object) -> _T: ... @abstractmethod - def __rtruediv__(self: Type[_T], other: object) -> _T: ... + def __rtruediv__(self: _T, other: object) -> _T: ... @abstractmethod - def __pow__(self: Type[_T], exponent: object) -> _T: ... + def __pow__(self: _T, exponent: object) -> _T: ... @abstractmethod - def __rpow__(self: Type[_T], base: object) -> _T: ... - def __abs__(self: Type[_T]) -> _T: ... - def conjugate(self: Type[_T]) -> _T: ... + def __rpow__(self: _T, base: object) -> _T: ... + def __abs__(self: _T) -> _T: ... + def conjugate(self: _T) -> _T: ... def __eq__(self, other: object) -> bool: ... if sys.version_info < (3, 0): def __ne__(self, other: object) -> bool: ... @@ -72,17 +72,17 @@ class Real(Complex, SupportsFloat): @abstractmethod def __ceil__(self) -> int: ... @abstractmethod - def __round__(self: Type[_T], ndigits: Optional[int] = ...) -> _T: ... - def __divmod__(self: Type[_T], other: object) -> _T: ... - def __rdivmod__(self: Type[_T], other: object) -> _T: ... + def __round__(self: _T, ndigits: Optional[int] = ...) -> _T: ... + def __divmod__(self: _T, other: object) -> _T: ... + def __rdivmod__(self: _T, other: object) -> _T: ... @abstractmethod - def __floordiv__(self: Type[_T], other: object) -> _T: ... + def __floordiv__(self: _T, other: object) -> _T: ... @abstractmethod - def __rfloordiv__(self: Type[_T], other: object) -> _T: ... + def __rfloordiv__(self: _T, other: object) -> _T: ... @abstractmethod - def __mod__(self: Type[_T], other: object) -> _T: ... + def __mod__(self: _T, other: object) -> _T: ... @abstractmethod - def __rmod__(self: Type[_T], other: object) -> _T: ... + def __rmod__(self: _T, other: object) -> _T: ... @abstractmethod def __lt__(self, other: object) -> bool: ... @abstractmethod @@ -92,7 +92,7 @@ class Real(Complex, SupportsFloat): def real(self) -> float: ... @property def imag(self) -> float: ... - def conjugate(self: Type[_T]) -> _T: ... + def conjugate(self: _T) -> _T: ... class Rational(Real): @property @@ -112,29 +112,29 @@ class Integral(Rational): def __long__(self) -> long: ... def __index__(self) -> int: ... @abstractmethod - def __pow__(self: Type[_T], exponent: object, modulus: Optional[Any] = ...) -> _T: ... + def __pow__(self: _T, exponent: object, modulus: Optional[Any] = ...) -> _T: ... @abstractmethod - def __lshift__(self: Type[_T], other: object) -> _T: ... + def __lshift__(self: _T, other: object) -> _T: ... @abstractmethod - def __rlshift__(self: Type[_T], other: object) -> _T: ... + def __rlshift__(self: _T, other: object) -> _T: ... @abstractmethod - def __rshift__(self: Type[_T], other: object) -> _T: ... + def __rshift__(self: _T, other: object) -> _T: ... @abstractmethod - def __rrshift__(self: Type[_T], other: object) -> _T: ... + def __rrshift__(self: _T, other: object) -> _T: ... @abstractmethod - def __and__(self: Type[_T], other: object) -> _T: ... + def __and__(self: _T, other: object) -> _T: ... @abstractmethod - def __rand__(self: Type[_T], other: object) -> _T: ... + def __rand__(self: _T, other: object) -> _T: ... @abstractmethod - def __xor__(self: Type[_T], other: object) -> _T: ... + def __xor__(self: _T, other: object) -> _T: ... @abstractmethod - def __rxor__(self: Type[_T], other: object) -> _T: ... + def __rxor__(self: _T, other: object) -> _T: ... @abstractmethod - def __or__(self: Type[_T], other: object) -> _T: ... + def __or__(self: _T, other: object) -> _T: ... @abstractmethod - def __ror__(self: Type[_T], other: object) -> _T: ... + def __ror__(self: _T, other: object) -> _T: ... @abstractmethod - def __invert__(self: Type[_T]) -> _T: ... + def __invert__(self: _T) -> _T: ... def __float__(self) -> float: ... @property def numerator(self) -> int: ... From 48513a87baedfd88c4feed87fd5d24759493c023 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Thu, 6 Aug 2020 17:13:15 -0700 Subject: [PATCH 03/14] Worked around error emitted by mypy. --- stdlib/2and3/numbers.pyi | 70 ++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/stdlib/2and3/numbers.pyi b/stdlib/2and3/numbers.pyi index 03664dc8aaa8..6f0c841c133a 100644 --- a/stdlib/2and3/numbers.pyi +++ b/stdlib/2and3/numbers.pyi @@ -24,42 +24,42 @@ class Complex(Number): def __nonzero__(self) -> bool: ... @property @abstractmethod - def real(self) -> float: ... + def real(self: _T) -> _T: ... @property @abstractmethod - def imag(self) -> float: ... + def imag(self: _T) -> _T: ... @abstractmethod - def __add__(self: _T, other: object) -> _T: ... + def __add__(self: _T, other: Any) -> _T: ... @abstractmethod - def __radd__(self: _T, other: object) -> _T: ... + def __radd__(self: _T, other: Any) -> _T: ... @abstractmethod def __neg__(self: _T) -> _T: ... @abstractmethod def __pos__(self: _T) -> _T: ... - def __sub__(self: _T, other: object) -> _T: ... - def __rsub__(self: _T, other: object) -> _T: ... + def __sub__(self: _T, other: Any) -> _T: ... + def __rsub__(self: _T, other: Any) -> _T: ... @abstractmethod - def __mul__(self: _T, other: object) -> _T: ... + def __mul__(self: _T, other: Any) -> _T: ... @abstractmethod - def __rmul__(self: _T, other: object) -> _T: ... + def __rmul__(self: _T, other: Any) -> _T: ... if sys.version_info < (3, 0): @abstractmethod def __div__(self, other): ... @abstractmethod def __rdiv__(self, other): ... @abstractmethod - def __truediv__(self: _T, other: object) -> _T: ... + def __truediv__(self: _T, other: Any) -> _T: ... @abstractmethod - def __rtruediv__(self: _T, other: object) -> _T: ... + def __rtruediv__(self: _T, other: Any) -> _T: ... @abstractmethod - def __pow__(self: _T, exponent: object) -> _T: ... + def __pow__(self: _T, exponent: Any) -> _T: ... @abstractmethod - def __rpow__(self: _T, base: object) -> _T: ... + def __rpow__(self: _T, base: Any) -> _T: ... def __abs__(self: _T) -> _T: ... def conjugate(self: _T) -> _T: ... - def __eq__(self, other: object) -> bool: ... + def __eq__(self, other: Any) -> bool: ... if sys.version_info < (3, 0): - def __ne__(self, other: object) -> bool: ... + def __ne__(self, other: Any) -> bool: ... class Real(Complex, SupportsFloat): @abstractmethod @@ -73,25 +73,25 @@ class Real(Complex, SupportsFloat): def __ceil__(self) -> int: ... @abstractmethod def __round__(self: _T, ndigits: Optional[int] = ...) -> _T: ... - def __divmod__(self: _T, other: object) -> _T: ... - def __rdivmod__(self: _T, other: object) -> _T: ... + def __divmod__(self: _T, other: Any) -> _T: ... + def __rdivmod__(self: _T, other: Any) -> _T: ... @abstractmethod - def __floordiv__(self: _T, other: object) -> _T: ... + def __floordiv__(self: _T, other: Any) -> _T: ... @abstractmethod - def __rfloordiv__(self: _T, other: object) -> _T: ... + def __rfloordiv__(self: _T, other: Any) -> _T: ... @abstractmethod - def __mod__(self: _T, other: object) -> _T: ... + def __mod__(self: _T, other: Any) -> _T: ... @abstractmethod - def __rmod__(self: _T, other: object) -> _T: ... + def __rmod__(self: _T, other: Any) -> _T: ... @abstractmethod - def __lt__(self, other: object) -> bool: ... + def __lt__(self, other: Any) -> bool: ... @abstractmethod - def __le__(self, other: object) -> bool: ... + def __le__(self, other: Any) -> bool: ... def __complex__(self) -> complex: ... @property - def real(self) -> float: ... + def real(self: _T) -> _T: ... @property - def imag(self) -> float: ... + def imag(self: _T) -> _T: ... def conjugate(self: _T) -> _T: ... class Rational(Real): @@ -112,27 +112,27 @@ class Integral(Rational): def __long__(self) -> long: ... def __index__(self) -> int: ... @abstractmethod - def __pow__(self: _T, exponent: object, modulus: Optional[Any] = ...) -> _T: ... + def __pow__(self: _T, exponent: Any, modulus: Optional[Any] = ...) -> _T: ... @abstractmethod - def __lshift__(self: _T, other: object) -> _T: ... + def __lshift__(self: _T, other: Any) -> _T: ... @abstractmethod - def __rlshift__(self: _T, other: object) -> _T: ... + def __rlshift__(self: _T, other: Any) -> _T: ... @abstractmethod - def __rshift__(self: _T, other: object) -> _T: ... + def __rshift__(self: _T, other: Any) -> _T: ... @abstractmethod - def __rrshift__(self: _T, other: object) -> _T: ... + def __rrshift__(self: _T, other: Any) -> _T: ... @abstractmethod - def __and__(self: _T, other: object) -> _T: ... + def __and__(self: _T, other: Any) -> _T: ... @abstractmethod - def __rand__(self: _T, other: object) -> _T: ... + def __rand__(self: _T, other: Any) -> _T: ... @abstractmethod - def __xor__(self: _T, other: object) -> _T: ... + def __xor__(self: _T, other: Any) -> _T: ... @abstractmethod - def __rxor__(self: _T, other: object) -> _T: ... + def __rxor__(self: _T, other: Any) -> _T: ... @abstractmethod - def __or__(self: _T, other: object) -> _T: ... + def __or__(self: _T, other: Any) -> _T: ... @abstractmethod - def __ror__(self: _T, other: object) -> _T: ... + def __ror__(self: _T, other: Any) -> _T: ... @abstractmethod def __invert__(self: _T) -> _T: ... def __float__(self) -> float: ... From 86f5ea570c189aeb44040aba6309a7a13e9b4fe8 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Thu, 6 Aug 2020 17:19:08 -0700 Subject: [PATCH 04/14] Fixed another issue found in CI test. --- stdlib/2and3/numbers.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/2and3/numbers.pyi b/stdlib/2and3/numbers.pyi index 6f0c841c133a..a3df3952d34e 100644 --- a/stdlib/2and3/numbers.pyi +++ b/stdlib/2and3/numbers.pyi @@ -76,9 +76,9 @@ class Real(Complex, SupportsFloat): def __divmod__(self: _T, other: Any) -> _T: ... def __rdivmod__(self: _T, other: Any) -> _T: ... @abstractmethod - def __floordiv__(self: _T, other: Any) -> _T: ... + def __floordiv__(self, other: Any) -> int: ... @abstractmethod - def __rfloordiv__(self: _T, other: Any) -> _T: ... + def __rfloordiv__(self, other: Any) -> int: ... @abstractmethod def __mod__(self: _T, other: Any) -> _T: ... @abstractmethod From 23fa7d5713b0602e42a9085e6467468ea7ffc3e4 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Thu, 6 Aug 2020 17:56:31 -0700 Subject: [PATCH 05/14] Removed extra line at bottom of file that my auto-formatter keeps adding. --- stdlib/2and3/fractions.pyi | 1 - stdlib/2and3/numbers.pyi | 1 - 2 files changed, 2 deletions(-) diff --git a/stdlib/2and3/fractions.pyi b/stdlib/2and3/fractions.pyi index c360ad001a00..dc2f489e1edf 100644 --- a/stdlib/2and3/fractions.pyi +++ b/stdlib/2and3/fractions.pyi @@ -83,4 +83,3 @@ class Fraction(Rational): @property def imag(self) -> Fraction: ... def conjugate(self) -> Fraction: ... - diff --git a/stdlib/2and3/numbers.pyi b/stdlib/2and3/numbers.pyi index a3df3952d34e..6b85bd07e899 100644 --- a/stdlib/2and3/numbers.pyi +++ b/stdlib/2and3/numbers.pyi @@ -140,4 +140,3 @@ class Integral(Rational): def numerator(self) -> int: ... @property def denominator(self) -> int: ... - From f7d16abbe77a58c80064516914abed39238fe8ed Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Fri, 7 Aug 2020 18:39:57 -0700 Subject: [PATCH 06/14] Incorporated code review feedback. Did a bunch of experimentation with Fraction objects to determine proper overloads for each magic method. --- stdlib/2and3/fractions.pyi | 98 ++++++++++++++++++++++++++++++-------- stdlib/2and3/numbers.pyi | 14 ++++-- 2 files changed, 86 insertions(+), 26 deletions(-) diff --git a/stdlib/2and3/fractions.pyi b/stdlib/2and3/fractions.pyi index dc2f489e1edf..18a4157896d8 100644 --- a/stdlib/2and3/fractions.pyi +++ b/stdlib/2and3/fractions.pyi @@ -7,7 +7,8 @@ import sys from decimal import Decimal from numbers import Integral, Rational, Real -from typing import Any, Optional, Tuple, Union, overload +from typing import Optional, Tuple, Union, overload +from typing_extensions import Literal _ComparableNum = Union[int, float, Decimal, Real] @@ -39,25 +40,77 @@ class Fraction(Rational): def numerator(self) -> int: ... @property def denominator(self) -> int: ... - def __add__(self, other: _ComparableNum) -> Fraction: ... - def __radd__(self, other: _ComparableNum) -> Fraction: ... - def __sub__(self, other: _ComparableNum) -> Fraction: ... - def __rsub__(self, other: _ComparableNum) -> Fraction: ... - def __mul__(self, other: _ComparableNum) -> Fraction: ... - def __rmul__(self, other: _ComparableNum) -> Fraction: ... - def __truediv__(self, other: _ComparableNum) -> Fraction: ... - def __rtruediv__(self, other: _ComparableNum) -> Fraction: ... + @overload + def __add__(self, other: Union[int, Fraction]) -> Fraction: ... + @overload + def __add__(self, other: float) -> float: ... + @overload + def __radd__(self, other: Union[int, Fraction]) -> Fraction: ... + @overload + def __radd__(self, other: float) -> float: ... + @overload + def __sub__(self, other: Union[int, Fraction]) -> Fraction: ... + @overload + def __sub__(self, other: float) -> float: ... + @overload + def __rsub__(self, other: Union[int, Fraction]) -> Fraction: ... + @overload + def __rsub__(self, other: float) -> float: ... + @overload + def __mul__(self, other: Union[int, Fraction]) -> Fraction: ... + @overload + def __mul__(self, other: float) -> float: ... + @overload + def __rmul__(self, other: Union[int, Fraction]) -> Fraction: ... + @overload + def __rmul__(self, other: float) -> float: ... + @overload + def __truediv__(self, other: Union[int, Fraction]) -> Fraction: ... + @overload + def __truediv__(self, other: float) -> float: ... + @overload + def __rtruediv__(self, other: Union[int, Fraction]) -> int: ... + @overload + def __rtruediv__(self, other: float) -> float: ... if sys.version_info < (3, 0): - def __div__(self, other): ... - def __rdiv__(self, other): ... - def __floordiv__(self, other: _ComparableNum) -> int: ... - def __rfloordiv__(self, other: _ComparableNum) -> int: ... - def __mod__(self, other: _ComparableNum) -> Fraction: ... - def __rmod__(self, other: _ComparableNum) -> Fraction: ... - def __divmod__(self, other: _ComparableNum) -> Fraction: ... - def __rdivmod__(self, other: _ComparableNum) -> Fraction: ... - def __pow__(self, other: _ComparableNum) -> Fraction: ... - def __rpow__(self, other: _ComparableNum) -> Fraction: ... + @overload + def __div__(self, other: Union[int, Fraction]) -> Fraction: ... + @overload + def __div__(self, other: float) -> float: ... + @overload + def __rdiv__(self, other: Union[int, Fraction]) -> Fraction: ... + @overload + def __rdiv__(self, other: float) -> float: ... + @overload + def __floordiv__(self, other: Union[int, Fraction]) -> int: ... + @overload + def __floordiv__(self, other: float) -> float: ... + @overload + def __rfloordiv__(self, other: Union[int, Fraction]) -> int: ... + @overload + def __rfloordiv__(self, other: float) -> float: ... + @overload + def __mod__(self, other: Union[int, Fraction]) -> Fraction: ... + @overload + def __mod__(self, other: float) -> float: ... + @overload + def __rmod__(self, other: Union[int, Fraction]) -> Fraction: ... + @overload + def __rmod__(self, other: float) -> float: ... + @overload + def __divmod__(self, other: Union[int, Fraction]) -> Tuple[int, Fraction]: ... + @overload + def __divmod__(self, other: float) -> Tuple[float, Fraction]: ... + @overload + def __rdivmod__(self, other: Union[int, Fraction]) -> Tuple[int, Fraction]: ... + @overload + def __rdivmod__(self, other: float) -> Tuple[float, Fraction]: ... + @overload + def __pow__(self, other: int) -> Fraction: ... + @overload + def __pow__(self, other: Union[float, Fraction]) -> float: ... + @overload + def __rpow__(self, other: Union[int, float, Fraction]) -> float: ... def __pos__(self) -> Fraction: ... def __neg__(self) -> Fraction: ... def __abs__(self) -> Fraction: ... @@ -65,7 +118,10 @@ class Fraction(Rational): if sys.version_info >= (3, 0): def __floor__(self) -> int: ... def __ceil__(self) -> int: ... - def __round__(self, ndigits: Optional[Any] = ...) -> Fraction: ... + @overload + def __round__(self) -> int: ... + @overload + def __round__(self, ndigits: int) -> Fraction: ... def __hash__(self) -> int: ... def __eq__(self, other: object) -> bool: ... def __lt__(self, other: _ComparableNum) -> bool: ... @@ -81,5 +137,5 @@ class Fraction(Rational): @property def real(self) -> Fraction: ... @property - def imag(self) -> Fraction: ... + def imag(self) -> Literal[0]: ... def conjugate(self) -> Fraction: ... diff --git a/stdlib/2and3/numbers.pyi b/stdlib/2and3/numbers.pyi index 6b85bd07e899..89b0ff822ab2 100644 --- a/stdlib/2and3/numbers.pyi +++ b/stdlib/2and3/numbers.pyi @@ -7,7 +7,7 @@ import sys from abc import ABCMeta, abstractmethod -from typing import Any, Optional, SupportsFloat, Type, TypeVar +from typing import Any, Optional, SupportsFloat, TypeVar, overload _T = TypeVar("_T") @@ -24,10 +24,10 @@ class Complex(Number): def __nonzero__(self) -> bool: ... @property @abstractmethod - def real(self: _T) -> _T: ... + def real(self) -> Real: ... @property @abstractmethod - def imag(self: _T) -> _T: ... + def imag(self) -> Real: ... @abstractmethod def __add__(self: _T, other: Any) -> _T: ... @abstractmethod @@ -55,7 +55,7 @@ class Complex(Number): def __pow__(self: _T, exponent: Any) -> _T: ... @abstractmethod def __rpow__(self: _T, base: Any) -> _T: ... - def __abs__(self: _T) -> _T: ... + def __abs__(self) -> Real: ... def conjugate(self: _T) -> _T: ... def __eq__(self, other: Any) -> bool: ... if sys.version_info < (3, 0): @@ -72,7 +72,11 @@ class Real(Complex, SupportsFloat): @abstractmethod def __ceil__(self) -> int: ... @abstractmethod - def __round__(self: _T, ndigits: Optional[int] = ...) -> _T: ... + @overload + def __round__(self) -> int: ... + @abstractmethod + @overload + def __round__(self: _T, ndigits: int) -> _T: ... def __divmod__(self: _T, other: Any) -> _T: ... def __rdivmod__(self: _T, other: Any) -> _T: ... @abstractmethod From c90aa229707c67c48566b548d71ff82125c9ca97 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Fri, 7 Aug 2020 18:48:08 -0700 Subject: [PATCH 07/14] Adjusted base class abstract method signatures. --- stdlib/2and3/numbers.pyi | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/stdlib/2and3/numbers.pyi b/stdlib/2and3/numbers.pyi index 89b0ff822ab2..c2cbae3f04d3 100644 --- a/stdlib/2and3/numbers.pyi +++ b/stdlib/2and3/numbers.pyi @@ -24,10 +24,10 @@ class Complex(Number): def __nonzero__(self) -> bool: ... @property @abstractmethod - def real(self) -> Real: ... + def real(self) -> Any: ... @property @abstractmethod - def imag(self) -> Real: ... + def imag(self) -> Any: ... @abstractmethod def __add__(self: _T, other: Any) -> _T: ... @abstractmethod @@ -48,13 +48,13 @@ class Complex(Number): @abstractmethod def __rdiv__(self, other): ... @abstractmethod - def __truediv__(self: _T, other: Any) -> _T: ... + def __truediv__(self, other: Any) -> Any: ... @abstractmethod - def __rtruediv__(self: _T, other: Any) -> _T: ... + def __rtruediv__(self, other: Any) -> Any: ... @abstractmethod - def __pow__(self: _T, exponent: Any) -> _T: ... + def __pow__(self, exponent: Any) -> Any: ... @abstractmethod - def __rpow__(self: _T, base: Any) -> _T: ... + def __rpow__(self, base: Any) -> Any: ... def __abs__(self) -> Real: ... def conjugate(self: _T) -> _T: ... def __eq__(self, other: Any) -> bool: ... @@ -77,8 +77,8 @@ class Real(Complex, SupportsFloat): @abstractmethod @overload def __round__(self: _T, ndigits: int) -> _T: ... - def __divmod__(self: _T, other: Any) -> _T: ... - def __rdivmod__(self: _T, other: Any) -> _T: ... + def __divmod__(self, other: Any) -> Any: ... + def __rdivmod__(self, other: Any) -> Any: ... @abstractmethod def __floordiv__(self, other: Any) -> int: ... @abstractmethod @@ -93,10 +93,10 @@ class Real(Complex, SupportsFloat): def __le__(self, other: Any) -> bool: ... def __complex__(self) -> complex: ... @property - def real(self: _T) -> _T: ... + def real(self) -> Any: ... @property - def imag(self: _T) -> _T: ... - def conjugate(self: _T) -> _T: ... + def imag(self) -> Any: ... + def conjugate(self) -> Any: ... class Rational(Real): @property From 52a23535469690b8a8ca12cfc8d4ebac00e20a06 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Fri, 7 Aug 2020 18:53:02 -0700 Subject: [PATCH 08/14] Fixed error caught by test. --- stdlib/2and3/fractions.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/2and3/fractions.pyi b/stdlib/2and3/fractions.pyi index 18a4157896d8..bf1d7c53bebd 100644 --- a/stdlib/2and3/fractions.pyi +++ b/stdlib/2and3/fractions.pyi @@ -69,7 +69,7 @@ class Fraction(Rational): @overload def __truediv__(self, other: float) -> float: ... @overload - def __rtruediv__(self, other: Union[int, Fraction]) -> int: ... + def __rtruediv__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __rtruediv__(self, other: float) -> float: ... if sys.version_info < (3, 0): From 596edbddfd111ba60106e27db2a25f6538c646bc Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Fri, 7 Aug 2020 18:55:31 -0700 Subject: [PATCH 09/14] Removed unnecessary overload. --- stdlib/2and3/fractions.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stdlib/2and3/fractions.pyi b/stdlib/2and3/fractions.pyi index bf1d7c53bebd..ece194de553a 100644 --- a/stdlib/2and3/fractions.pyi +++ b/stdlib/2and3/fractions.pyi @@ -109,7 +109,6 @@ class Fraction(Rational): def __pow__(self, other: int) -> Fraction: ... @overload def __pow__(self, other: Union[float, Fraction]) -> float: ... - @overload def __rpow__(self, other: Union[int, float, Fraction]) -> float: ... def __pos__(self) -> Fraction: ... def __neg__(self) -> Fraction: ... From c1b7f4aa73e48abceffb727eb8cfdeac30407ba2 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Fri, 7 Aug 2020 19:01:38 -0700 Subject: [PATCH 10/14] Fixed error in __round__ identified by stubtest. --- stdlib/2and3/fractions.pyi | 4 ++-- stdlib/2and3/numbers.pyi | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/2and3/fractions.pyi b/stdlib/2and3/fractions.pyi index ece194de553a..f0f1d8c81cc2 100644 --- a/stdlib/2and3/fractions.pyi +++ b/stdlib/2and3/fractions.pyi @@ -118,9 +118,9 @@ class Fraction(Rational): def __floor__(self) -> int: ... def __ceil__(self) -> int: ... @overload - def __round__(self) -> int: ... - @overload def __round__(self, ndigits: int) -> Fraction: ... + @overload + def __round__(self, ndigits: None = ...) -> int: ... def __hash__(self) -> int: ... def __eq__(self, other: object) -> bool: ... def __lt__(self, other: _ComparableNum) -> bool: ... diff --git a/stdlib/2and3/numbers.pyi b/stdlib/2and3/numbers.pyi index c2cbae3f04d3..2343370f3b9f 100644 --- a/stdlib/2and3/numbers.pyi +++ b/stdlib/2and3/numbers.pyi @@ -73,10 +73,10 @@ class Real(Complex, SupportsFloat): def __ceil__(self) -> int: ... @abstractmethod @overload - def __round__(self) -> int: ... + def __round__(self: _T, ndigits: int) -> _T: ... @abstractmethod @overload - def __round__(self: _T, ndigits: int) -> _T: ... + def __round__(self, ndigits: None = ...) -> int: ... def __divmod__(self, other: Any) -> Any: ... def __rdivmod__(self, other: Any) -> Any: ... @abstractmethod From ad863f73228b8f23545cbbe076040bc706c50080 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Tue, 11 Aug 2020 09:14:11 -0700 Subject: [PATCH 11/14] Made changes based on PR feedback. --- stdlib/2and3/fractions.pyi | 25 ++++++++++++++++++ stdlib/2and3/numbers.pyi | 52 ++++++++++++++++++-------------------- 2 files changed, 50 insertions(+), 27 deletions(-) diff --git a/stdlib/2and3/fractions.pyi b/stdlib/2and3/fractions.pyi index f0f1d8c81cc2..5fdbad691573 100644 --- a/stdlib/2and3/fractions.pyi +++ b/stdlib/2and3/fractions.pyi @@ -43,44 +43,64 @@ class Fraction(Rational): @overload def __add__(self, other: Union[int, Fraction]) -> Fraction: ... @overload + def __add__(self, other: complex) -> complex: ... + @overload def __add__(self, other: float) -> float: ... @overload def __radd__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __radd__(self, other: float) -> float: ... @overload + def __radd__(self, other: complex) -> complex: ... + @overload def __sub__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __sub__(self, other: float) -> float: ... @overload + def __sub__(self, other: complex) -> complex: ... + @overload def __rsub__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __rsub__(self, other: float) -> float: ... @overload + def __rsub__(self, other: complex) -> complex: ... + @overload def __mul__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __mul__(self, other: float) -> float: ... @overload + def __mul__(self, other: complex) -> complex: ... + @overload def __rmul__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __rmul__(self, other: float) -> float: ... @overload + def __rmul__(self, other: complex) -> complex: ... + @overload def __truediv__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __truediv__(self, other: float) -> float: ... @overload + def __truediv__(self, other: complex) -> complex: ... + @overload def __rtruediv__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __rtruediv__(self, other: float) -> float: ... + @overload + def __rtruediv__(self, other: complex) -> complex: ... if sys.version_info < (3, 0): @overload def __div__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __div__(self, other: float) -> float: ... @overload + def __div__(self, other: complex) -> complex: ... + @overload def __rdiv__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __rdiv__(self, other: float) -> float: ... + @overload + def __rdiv__(self, other: complex) -> complex: ... @overload def __floordiv__(self, other: Union[int, Fraction]) -> int: ... @overload @@ -109,7 +129,12 @@ class Fraction(Rational): def __pow__(self, other: int) -> Fraction: ... @overload def __pow__(self, other: Union[float, Fraction]) -> float: ... + @overload + def __pow__(self, other: complex) -> complex: ... + @overload def __rpow__(self, other: Union[int, float, Fraction]) -> float: ... + @overload + def __rpow__(self, other: complex) -> complex: ... def __pos__(self) -> Fraction: ... def __neg__(self) -> Fraction: ... def __abs__(self) -> Fraction: ... diff --git a/stdlib/2and3/numbers.pyi b/stdlib/2and3/numbers.pyi index 2343370f3b9f..ccbc1cc23529 100644 --- a/stdlib/2and3/numbers.pyi +++ b/stdlib/2and3/numbers.pyi @@ -7,9 +7,7 @@ import sys from abc import ABCMeta, abstractmethod -from typing import Any, Optional, SupportsFloat, TypeVar, overload - -_T = TypeVar("_T") +from typing import Any, Optional, SupportsFloat, overload class Number(metaclass=ABCMeta): @abstractmethod @@ -29,19 +27,19 @@ class Complex(Number): @abstractmethod def imag(self) -> Any: ... @abstractmethod - def __add__(self: _T, other: Any) -> _T: ... + def __add__(self, other: Any) -> Any: ... @abstractmethod - def __radd__(self: _T, other: Any) -> _T: ... + def __radd__(self, other: Any) -> Any: ... @abstractmethod - def __neg__(self: _T) -> _T: ... + def __neg__(self) -> Any: ... @abstractmethod - def __pos__(self: _T) -> _T: ... - def __sub__(self: _T, other: Any) -> _T: ... - def __rsub__(self: _T, other: Any) -> _T: ... + def __pos__(self) -> Any: ... + def __sub__(self, other: Any) -> Any: ... + def __rsub__(self, other: Any) -> Any: ... @abstractmethod - def __mul__(self: _T, other: Any) -> _T: ... + def __mul__(self, other: Any) -> Any: ... @abstractmethod - def __rmul__(self: _T, other: Any) -> _T: ... + def __rmul__(self, other: Any) -> Any: ... if sys.version_info < (3, 0): @abstractmethod def __div__(self, other): ... @@ -56,7 +54,7 @@ class Complex(Number): @abstractmethod def __rpow__(self, base: Any) -> Any: ... def __abs__(self) -> Real: ... - def conjugate(self: _T) -> _T: ... + def conjugate(self) -> Any: ... def __eq__(self, other: Any) -> bool: ... if sys.version_info < (3, 0): def __ne__(self, other: Any) -> bool: ... @@ -73,7 +71,7 @@ class Real(Complex, SupportsFloat): def __ceil__(self) -> int: ... @abstractmethod @overload - def __round__(self: _T, ndigits: int) -> _T: ... + def __round__(self, ndigits: int) -> Any: ... @abstractmethod @overload def __round__(self, ndigits: None = ...) -> int: ... @@ -84,9 +82,9 @@ class Real(Complex, SupportsFloat): @abstractmethod def __rfloordiv__(self, other: Any) -> int: ... @abstractmethod - def __mod__(self: _T, other: Any) -> _T: ... + def __mod__(self, other: Any) -> Any: ... @abstractmethod - def __rmod__(self: _T, other: Any) -> _T: ... + def __rmod__(self, other: Any) -> Any: ... @abstractmethod def __lt__(self, other: Any) -> bool: ... @abstractmethod @@ -116,29 +114,29 @@ class Integral(Rational): def __long__(self) -> long: ... def __index__(self) -> int: ... @abstractmethod - def __pow__(self: _T, exponent: Any, modulus: Optional[Any] = ...) -> _T: ... + def __pow__(self, exponent: Any, modulus: Optional[Any] = ...) -> Any: ... @abstractmethod - def __lshift__(self: _T, other: Any) -> _T: ... + def __lshift__(self, other: Any) -> Any: ... @abstractmethod - def __rlshift__(self: _T, other: Any) -> _T: ... + def __rlshift__(self, other: Any) -> Any: ... @abstractmethod - def __rshift__(self: _T, other: Any) -> _T: ... + def __rshift__(self, other: Any) -> Any: ... @abstractmethod - def __rrshift__(self: _T, other: Any) -> _T: ... + def __rrshift__(self, other: Any) -> Any: ... @abstractmethod - def __and__(self: _T, other: Any) -> _T: ... + def __and__(self, other: Any) -> Any: ... @abstractmethod - def __rand__(self: _T, other: Any) -> _T: ... + def __rand__(self, other: Any) -> Any: ... @abstractmethod - def __xor__(self: _T, other: Any) -> _T: ... + def __xor__(self, other: Any) -> Any: ... @abstractmethod - def __rxor__(self: _T, other: Any) -> _T: ... + def __rxor__(self, other: Any) -> Any: ... @abstractmethod - def __or__(self: _T, other: Any) -> _T: ... + def __or__(self, other: Any) -> Any: ... @abstractmethod - def __ror__(self: _T, other: Any) -> _T: ... + def __ror__(self, other: Any) -> Any: ... @abstractmethod - def __invert__(self: _T) -> _T: ... + def __invert__(self) -> Any: ... def __float__(self) -> float: ... @property def numerator(self) -> int: ... From 911e8f940c7f979b57159fe023dc4055036735d1 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Tue, 11 Aug 2020 09:18:04 -0700 Subject: [PATCH 12/14] Fixed overload ordering issue --- stdlib/2and3/fractions.pyi | 42 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/stdlib/2and3/fractions.pyi b/stdlib/2and3/fractions.pyi index 5fdbad691573..6bb97357ce88 100644 --- a/stdlib/2and3/fractions.pyi +++ b/stdlib/2and3/fractions.pyi @@ -49,58 +49,58 @@ class Fraction(Rational): @overload def __radd__(self, other: Union[int, Fraction]) -> Fraction: ... @overload - def __radd__(self, other: float) -> float: ... - @overload def __radd__(self, other: complex) -> complex: ... @overload - def __sub__(self, other: Union[int, Fraction]) -> Fraction: ... + def __radd__(self, other: float) -> float: ... @overload - def __sub__(self, other: float) -> float: ... + def __sub__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __sub__(self, other: complex) -> complex: ... @overload - def __rsub__(self, other: Union[int, Fraction]) -> Fraction: ... + def __sub__(self, other: float) -> float: ... @overload - def __rsub__(self, other: float) -> float: ... + def __rsub__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __rsub__(self, other: complex) -> complex: ... @overload - def __mul__(self, other: Union[int, Fraction]) -> Fraction: ... + def __rsub__(self, other: float) -> float: ... @overload - def __mul__(self, other: float) -> float: ... + def __mul__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __mul__(self, other: complex) -> complex: ... @overload - def __rmul__(self, other: Union[int, Fraction]) -> Fraction: ... + def __mul__(self, other: float) -> float: ... @overload - def __rmul__(self, other: float) -> float: ... + def __rmul__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __rmul__(self, other: complex) -> complex: ... @overload - def __truediv__(self, other: Union[int, Fraction]) -> Fraction: ... + def __rmul__(self, other: float) -> float: ... @overload - def __truediv__(self, other: float) -> float: ... + def __truediv__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __truediv__(self, other: complex) -> complex: ... @overload - def __rtruediv__(self, other: Union[int, Fraction]) -> Fraction: ... + def __truediv__(self, other: float) -> float: ... @overload - def __rtruediv__(self, other: float) -> float: ... + def __rtruediv__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __rtruediv__(self, other: complex) -> complex: ... + @overload + def __rtruediv__(self, other: float) -> float: ... if sys.version_info < (3, 0): @overload def __div__(self, other: Union[int, Fraction]) -> Fraction: ... @overload - def __div__(self, other: float) -> float: ... - @overload def __div__(self, other: complex) -> complex: ... @overload - def __rdiv__(self, other: Union[int, Fraction]) -> Fraction: ... + def __div__(self, other: float) -> float: ... @overload - def __rdiv__(self, other: float) -> float: ... + def __rdiv__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __rdiv__(self, other: complex) -> complex: ... + @overload + def __rdiv__(self, other: float) -> float: ... @overload def __floordiv__(self, other: Union[int, Fraction]) -> int: ... @overload @@ -128,13 +128,13 @@ class Fraction(Rational): @overload def __pow__(self, other: int) -> Fraction: ... @overload - def __pow__(self, other: Union[float, Fraction]) -> float: ... - @overload def __pow__(self, other: complex) -> complex: ... @overload - def __rpow__(self, other: Union[int, float, Fraction]) -> float: ... + def __pow__(self, other: Union[float, Fraction]) -> float: ... @overload def __rpow__(self, other: complex) -> complex: ... + @overload + def __rpow__(self, other: Union[int, float, Fraction]) -> float: ... def __pos__(self) -> Fraction: ... def __neg__(self) -> Fraction: ... def __abs__(self) -> Fraction: ... From 1f280ca6101ca3124247952030effee0e129e274 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Tue, 11 Aug 2020 09:21:24 -0700 Subject: [PATCH 13/14] Fixed more stubtest errors --- stdlib/2and3/fractions.pyi | 42 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/stdlib/2and3/fractions.pyi b/stdlib/2and3/fractions.pyi index 6bb97357ce88..7ac1eb747b0e 100644 --- a/stdlib/2and3/fractions.pyi +++ b/stdlib/2and3/fractions.pyi @@ -43,10 +43,10 @@ class Fraction(Rational): @overload def __add__(self, other: Union[int, Fraction]) -> Fraction: ... @overload - def __add__(self, other: complex) -> complex: ... - @overload def __add__(self, other: float) -> float: ... @overload + def __add__(self, other: complex) -> complex: ... + @overload def __radd__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __radd__(self, other: complex) -> complex: ... @@ -55,52 +55,52 @@ class Fraction(Rational): @overload def __sub__(self, other: Union[int, Fraction]) -> Fraction: ... @overload - def __sub__(self, other: complex) -> complex: ... - @overload def __sub__(self, other: float) -> float: ... @overload - def __rsub__(self, other: Union[int, Fraction]) -> Fraction: ... + def __sub__(self, other: complex) -> complex: ... @overload - def __rsub__(self, other: complex) -> complex: ... + def __rsub__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __rsub__(self, other: float) -> float: ... @overload - def __mul__(self, other: Union[int, Fraction]) -> Fraction: ... + def __rsub__(self, other: complex) -> complex: ... @overload - def __mul__(self, other: complex) -> complex: ... + def __mul__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __mul__(self, other: float) -> float: ... @overload - def __rmul__(self, other: Union[int, Fraction]) -> Fraction: ... + def __mul__(self, other: complex) -> complex: ... @overload - def __rmul__(self, other: complex) -> complex: ... + def __rmul__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __rmul__(self, other: float) -> float: ... @overload - def __truediv__(self, other: Union[int, Fraction]) -> Fraction: ... + def __rmul__(self, other: complex) -> complex: ... @overload - def __truediv__(self, other: complex) -> complex: ... + def __truediv__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __truediv__(self, other: float) -> float: ... @overload - def __rtruediv__(self, other: Union[int, Fraction]) -> Fraction: ... + def __truediv__(self, other: complex) -> complex: ... @overload - def __rtruediv__(self, other: complex) -> complex: ... + def __rtruediv__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __rtruediv__(self, other: float) -> float: ... + @overload + def __rtruediv__(self, other: complex) -> complex: ... if sys.version_info < (3, 0): @overload def __div__(self, other: Union[int, Fraction]) -> Fraction: ... @overload - def __div__(self, other: complex) -> complex: ... - @overload def __div__(self, other: float) -> float: ... @overload - def __rdiv__(self, other: Union[int, Fraction]) -> Fraction: ... + def __div__(self, other: complex) -> complex: ... @overload - def __rdiv__(self, other: complex) -> complex: ... + def __rdiv__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __rdiv__(self, other: float) -> float: ... + @overload + def __rdiv__(self, other: complex) -> complex: ... @overload def __floordiv__(self, other: Union[int, Fraction]) -> int: ... @overload @@ -128,13 +128,13 @@ class Fraction(Rational): @overload def __pow__(self, other: int) -> Fraction: ... @overload - def __pow__(self, other: complex) -> complex: ... - @overload def __pow__(self, other: Union[float, Fraction]) -> float: ... @overload - def __rpow__(self, other: complex) -> complex: ... + def __pow__(self, other: complex) -> complex: ... @overload def __rpow__(self, other: Union[int, float, Fraction]) -> float: ... + @overload + def __rpow__(self, other: complex) -> complex: ... def __pos__(self) -> Fraction: ... def __neg__(self) -> Fraction: ... def __abs__(self) -> Fraction: ... From 55755f67009632efbc55fde24afcf36459404170 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Tue, 11 Aug 2020 09:23:45 -0700 Subject: [PATCH 14/14] Missed one more overload order issue --- stdlib/2and3/fractions.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/2and3/fractions.pyi b/stdlib/2and3/fractions.pyi index 7ac1eb747b0e..355489bc6d5a 100644 --- a/stdlib/2and3/fractions.pyi +++ b/stdlib/2and3/fractions.pyi @@ -49,10 +49,10 @@ class Fraction(Rational): @overload def __radd__(self, other: Union[int, Fraction]) -> Fraction: ... @overload - def __radd__(self, other: complex) -> complex: ... - @overload def __radd__(self, other: float) -> float: ... @overload + def __radd__(self, other: complex) -> complex: ... + @overload def __sub__(self, other: Union[int, Fraction]) -> Fraction: ... @overload def __sub__(self, other: float) -> float: ...