|
| 1 | +# Stubs for numbers (Python 3.5) |
| 2 | +# See https://docs.python.org/2.7/library/numbers.html |
| 3 | +# and https://docs.python.org/3/library/numbers.html |
| 4 | +# |
| 5 | +# Note: these stubs are incomplete. The more complex type |
| 6 | +# signatures are currently omitted. |
| 7 | + |
| 8 | +from typing import Any, Optional, TypeVar |
| 9 | +from abc import ABCMeta, abstractmethod |
| 10 | +import sys |
| 11 | + |
| 12 | +class Number(metaclass=ABCMeta): |
| 13 | + @abstractmethod |
| 14 | + def __hash__(self) -> int: ... |
| 15 | + |
| 16 | +class Complex(Number): |
| 17 | + @abstractmethod |
| 18 | + def __complex__(self) -> complex: ... |
| 19 | + if sys.version_info >= (3, 0): |
| 20 | + def __bool__(self) -> bool: ... |
| 21 | + else: |
| 22 | + def __nonzero__(self) -> bool: ... |
| 23 | + @property |
| 24 | + @abstractmethod |
| 25 | + def real(self): ... |
| 26 | + @property |
| 27 | + @abstractmethod |
| 28 | + def imag(self): ... |
| 29 | + @abstractmethod |
| 30 | + def __add__(self, other): ... |
| 31 | + @abstractmethod |
| 32 | + def __radd__(self, other): ... |
| 33 | + @abstractmethod |
| 34 | + def __neg__(self): ... |
| 35 | + @abstractmethod |
| 36 | + def __pos__(self): ... |
| 37 | + def __sub__(self, other): ... |
| 38 | + def __rsub__(self, other): ... |
| 39 | + @abstractmethod |
| 40 | + def __mul__(self, other): ... |
| 41 | + @abstractmethod |
| 42 | + def __rmul__(self, other): ... |
| 43 | + if sys.version_info < (3, 0): |
| 44 | + @abstractmethod |
| 45 | + def __div__(self, other): ... |
| 46 | + @abstractmethod |
| 47 | + def __rdiv__(self, other): ... |
| 48 | + @abstractmethod |
| 49 | + def __truediv__(self, other): ... |
| 50 | + @abstractmethod |
| 51 | + def __rtruediv__(self, other): ... |
| 52 | + @abstractmethod |
| 53 | + def __pow__(self, exponent): ... |
| 54 | + @abstractmethod |
| 55 | + def __rpow__(self, base): ... |
| 56 | + def __abs__(self): ... |
| 57 | + def conjugate(self): ... |
| 58 | + def __eq__(self, other: object) -> bool: ... |
| 59 | + if sys.version_info < (3, 0): |
| 60 | + def __ne__(self, other: object) -> bool: ... |
| 61 | + |
| 62 | +class Real(Complex): |
| 63 | + @abstractmethod |
| 64 | + def __float__(self) -> float: ... |
| 65 | + @abstractmethod |
| 66 | + def __trunc__(self) -> int: ... |
| 67 | + if sys.version_info >= (3, 0): |
| 68 | + @abstractmethod |
| 69 | + def __floor__(self) -> int: ... |
| 70 | + @abstractmethod |
| 71 | + def __ceil__(self) -> int: ... |
| 72 | + @abstractmethod |
| 73 | + def __round__(self, ndigits: Optional[int] = None): ... |
| 74 | + def __divmod__(self, other): ... |
| 75 | + def __rdivmod__(self, other): ... |
| 76 | + @abstractmethod |
| 77 | + def __floordiv__(self, other): ... |
| 78 | + @abstractmethod |
| 79 | + def __rfloordiv__(self, other): ... |
| 80 | + @abstractmethod |
| 81 | + def __mod__(self, other): ... |
| 82 | + @abstractmethod |
| 83 | + def __rmod__(self, other): ... |
| 84 | + @abstractmethod |
| 85 | + def __lt__(self, other) -> bool: ... |
| 86 | + @abstractmethod |
| 87 | + def __le__(self, other) -> bool: ... |
| 88 | + def __complex__(self) -> complex: ... |
| 89 | + @property |
| 90 | + def real(self): ... |
| 91 | + @property |
| 92 | + def imag(self): ... |
| 93 | + def conjugate(self): ... |
| 94 | + |
| 95 | +class Rational(Real): |
| 96 | + @property |
| 97 | + @abstractmethod |
| 98 | + def numerator(self) -> int: ... |
| 99 | + @property |
| 100 | + @abstractmethod |
| 101 | + def denominator(self) -> int: ... |
| 102 | + def __float__(self) -> float: ... |
| 103 | + |
| 104 | +class Integral(Rational): |
| 105 | + if sys.version_info >= (3, 0): |
| 106 | + @abstractmethod |
| 107 | + def __int__(self) -> int: ... |
| 108 | + else: |
| 109 | + @abstractmethod |
| 110 | + def __long__(self) -> long: ... |
| 111 | + def __index__(self) -> int: ... |
| 112 | + @abstractmethod |
| 113 | + def __pow__(self, exponent, modulus=None): ... |
| 114 | + @abstractmethod |
| 115 | + def __lshift__(self, other): ... |
| 116 | + @abstractmethod |
| 117 | + def __rlshift__(self, other): ... |
| 118 | + @abstractmethod |
| 119 | + def __rshift__(self, other): ... |
| 120 | + @abstractmethod |
| 121 | + def __rrshift__(self, other): ... |
| 122 | + @abstractmethod |
| 123 | + def __and__(self, other): ... |
| 124 | + @abstractmethod |
| 125 | + def __rand__(self, other): ... |
| 126 | + @abstractmethod |
| 127 | + def __xor__(self, other): ... |
| 128 | + @abstractmethod |
| 129 | + def __rxor__(self, other): ... |
| 130 | + @abstractmethod |
| 131 | + def __or__(self, other): ... |
| 132 | + @abstractmethod |
| 133 | + def __ror__(self, other): ... |
| 134 | + @abstractmethod |
| 135 | + def __invert__(self): ... |
| 136 | + def __float__(self) -> float: ... |
| 137 | + @property |
| 138 | + def numerator(self) -> int: ... |
| 139 | + @property |
| 140 | + def denominator(self) -> int: ... |
0 commit comments