From 24817abf8321f50253f115635131dfa955f1e9d3 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Tue, 13 Sep 2016 20:53:52 -0700 Subject: [PATCH 1/3] Partially refine numbers.pyi This commit refines numbers.pyi. More specifically, it... - Adds in explicit type annotations where it's obvious how to do so (leaving more non-obvious type signatures alone). - Adds in missing '@abstractmethod' decorators - Combines together the Python 2 and Python 3 versions of numbers.pyi. --- stdlib/3/numbers.pyi | 102 +++++++++++++++++++++++++++++++++---------- 1 file changed, 80 insertions(+), 22 deletions(-) diff --git a/stdlib/3/numbers.pyi b/stdlib/3/numbers.pyi index 8bea0b0222da..2e173f8ec2fa 100644 --- a/stdlib/3/numbers.pyi +++ b/stdlib/3/numbers.pyi @@ -1,50 +1,89 @@ # Stubs for numbers (Python 3.5) +# # # NOTE: This dynamically typed stub was automatically generated by stubgen. -from typing import Any +from typing import Any, Optional, TypeVar +from abc import ABCMeta, abstractmethod +import sys -class Number: - __hash__ = ... # type: Any +class Number(metaclass=ABCMeta): + @abstractmethod + def __hash__(self) -> int: ... class Complex(Number): - def __complex__(self): ... - def __bool__(self): ... + @abstractmethod + def __complex__(self) -> complex: ... + if sys.version_info >= (3, 0): + def __bool__(self) -> bool: ... + else: + def __nonzero__(self) -> bool: ... @property + @abstractmethod def real(self): ... @property + @abstractmethod def imag(self): ... + @abstractmethod def __add__(self, other): ... + @abstractmethod def __radd__(self, other): ... + @abstractmethod def __neg__(self): ... + @abstractmethod def __pos__(self): ... def __sub__(self, other): ... def __rsub__(self, other): ... + @abstractmethod def __mul__(self, other): ... + @abstractmethod def __rmul__(self, other): ... + if sys.version_info < (3, 0): + @abstractmethod + def __div__(self, other): ... + @abstractmethod + def __rdiv__(self, other): ... + @abstractmethod def __truediv__(self, other): ... + @abstractmethod def __rtruediv__(self, other): ... + @abstractmethod def __pow__(self, exponent): ... + @abstractmethod def __rpow__(self, base): ... def __abs__(self): ... def conjugate(self): ... - def __eq__(self, other): ... + def __eq__(self, other: object) -> bool: ... + if sys.version_info < (3, 0): + def __ne__(self, other: object) -> bool: ... class Real(Complex): - def __float__(self): ... - def __trunc__(self): ... - def __floor__(self): ... - def __ceil__(self): ... - def __round__(self, ndigits=None): ... + @abstractmethod + def __float__(self) -> float: ... + @abstractmethod + def __trunc__(self) -> int: ... + if sys.version_info >= (3, 0): + @abstractmethod + def __floor__(self) -> int: ... + @abstractmethod + def __ceil__(self) -> int: ... + @abstractmethod + def __round__(self, ndigits: Optional[int] = None): ... def __divmod__(self, other): ... def __rdivmod__(self, other): ... + @abstractmethod def __floordiv__(self, other): ... + @abstractmethod def __rfloordiv__(self, other): ... + @abstractmethod def __mod__(self, other): ... + @abstractmethod def __rmod__(self, other): ... - def __lt__(self, other): ... - def __le__(self, other): ... - def __complex__(self): ... + @abstractmethod + def __lt__(self, other) -> bool: ... + @abstractmethod + def __le__(self, other) -> bool: ... + def __complex__(self) -> complex: ... @property def real(self): ... @property @@ -53,28 +92,47 @@ class Real(Complex): class Rational(Real): @property - def numerator(self): ... + @abstractmethod + def numerator(self) -> int: ... @property - def denominator(self): ... - def __float__(self): ... + @abstractmethod + def denominator(self) -> int: ... + def __float__(self) -> float: ... class Integral(Rational): - def __int__(self): ... - def __index__(self): ... + if sys.version_info >= (3, 0): + @abstractmethod + def __int__(self) -> int: ... + else: + @abstractmethod + def __long__(self) -> long: ... + def __index__(self) -> int: ... + @abstractmethod def __pow__(self, exponent, modulus=None): ... + @abstractmethod def __lshift__(self, other): ... + @abstractmethod def __rlshift__(self, other): ... + @abstractmethod def __rshift__(self, other): ... + @abstractmethod def __rrshift__(self, other): ... + @abstractmethod def __and__(self, other): ... + @abstractmethod def __rand__(self, other): ... + @abstractmethod def __xor__(self, other): ... + @abstractmethod def __rxor__(self, other): ... + @abstractmethod def __or__(self, other): ... + @abstractmethod def __ror__(self, other): ... + @abstractmethod def __invert__(self): ... - def __float__(self): ... + def __float__(self) -> float: ... @property - def numerator(self): ... + def numerator(self) -> int: ... @property - def denominator(self): ... + def denominator(self) -> int: ... From c4ef16ffd2b8c423a01ac0cc249ab89ec6cd8dfc Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Tue, 13 Sep 2016 20:55:44 -0700 Subject: [PATCH 2/3] Merges Python 2 and Python 3 numbers.pyi This commit removes the old `stdlib/2.7/numbers.pyi` file and moves the previously-committed `stdlib/3/numbers.pyi` to the shared `2and3` directory. --- stdlib/2.7/numbers.pyi | 77 --------------------------------- stdlib/{3 => 2and3}/numbers.pyi | 0 2 files changed, 77 deletions(-) delete mode 100644 stdlib/2.7/numbers.pyi rename stdlib/{3 => 2and3}/numbers.pyi (100%) diff --git a/stdlib/2.7/numbers.pyi b/stdlib/2.7/numbers.pyi deleted file mode 100644 index f55611a2af3a..000000000000 --- a/stdlib/2.7/numbers.pyi +++ /dev/null @@ -1,77 +0,0 @@ -# Stubs for numbers (Python 2) -# -# NOTE: This dynamically typed stub was automatically generated by stubgen. - -from typing import Any - -class Number: - __metaclass__ = ... # type: Any - __hash__ = ... # type: Any - -class Complex(Number): - def __complex__(self): ... - def __nonzero__(self): ... - def real(self): ... - def imag(self): ... - def __add__(self, other): ... - def __radd__(self, other): ... - def __neg__(self): ... - def __pos__(self): ... - def __sub__(self, other): ... - def __rsub__(self, other): ... - def __mul__(self, other): ... - def __rmul__(self, other): ... - def __div__(self, other): ... - def __rdiv__(self, other): ... - def __truediv__(self, other): ... - def __rtruediv__(self, other): ... - def __pow__(self, exponent): ... - def __rpow__(self, base): ... - def __abs__(self): ... - def conjugate(self): ... - def __eq__(self, other): ... - def __ne__(self, other): ... - -class Real(Complex): - def __float__(self): ... - def __trunc__(self): ... - def __divmod__(self, other): ... - def __rdivmod__(self, other): ... - def __floordiv__(self, other): ... - def __rfloordiv__(self, other): ... - def __mod__(self, other): ... - def __rmod__(self, other): ... - def __lt__(self, other): ... - def __le__(self, other): ... - def __complex__(self): ... - @property - def real(self): ... - @property - def imag(self): ... - def conjugate(self): ... - -class Rational(Real): - def numerator(self): ... - def denominator(self): ... - def __float__(self): ... - -class Integral(Rational): - def __long__(self): ... - def __index__(self): ... - def __pow__(self, exponent, modulus=...): ... - def __lshift__(self, other): ... - def __rlshift__(self, other): ... - def __rshift__(self, other): ... - def __rrshift__(self, other): ... - def __and__(self, other): ... - def __rand__(self, other): ... - def __xor__(self, other): ... - def __rxor__(self, other): ... - def __or__(self, other): ... - def __ror__(self, other): ... - def __invert__(self): ... - def __float__(self): ... - @property - def numerator(self): ... - @property - def denominator(self): ... diff --git a/stdlib/3/numbers.pyi b/stdlib/2and3/numbers.pyi similarity index 100% rename from stdlib/3/numbers.pyi rename to stdlib/2and3/numbers.pyi From bc3bbe40300c9ff51d0ba3e5cbfaea0bdbbd2011 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Tue, 13 Sep 2016 21:03:09 -0700 Subject: [PATCH 3/3] Modify comment at top of numbers.pyi Since the stubs are no longer identical to what stubgen creates, the comment should also probably be changed. --- stdlib/2and3/numbers.pyi | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stdlib/2and3/numbers.pyi b/stdlib/2and3/numbers.pyi index 2e173f8ec2fa..e4f7603e62f8 100644 --- a/stdlib/2and3/numbers.pyi +++ b/stdlib/2and3/numbers.pyi @@ -1,7 +1,9 @@ # Stubs for numbers (Python 3.5) -# +# See https://docs.python.org/2.7/library/numbers.html +# and https://docs.python.org/3/library/numbers.html # -# NOTE: This dynamically typed stub was automatically generated by stubgen. +# Note: these stubs are incomplete. The more complex type +# signatures are currently omitted. from typing import Any, Optional, TypeVar from abc import ABCMeta, abstractmethod