Refine stubs for Python 2's decimal module (#545)

* Refine stubs for Python 2's decimal module

The decimal module for Python 2 was relatively incomplete, unlike the
decimal module for Python 3. This commit copies the relevant type
signatures from Python 3's decimal module to Python 2's.

There was a lot of code in both stubs and it wasn't clear to me if it
was safe to merge the two modules together, so I refrained from doing
so.

* Allow comparisions with Decimals and Floats

This commit loosens the types for Decimals to allow comparisons like
`Decimal('3.14') < 4.2`. Previously, you could compare decimals with
only other decimals or ints.
This commit is contained in:
Michael Lee
2016-09-14 09:40:14 -07:00
committed by Guido van Rossum
parent f29a996501
commit 748428d8a4
2 changed files with 135 additions and 120 deletions

View File

@@ -6,6 +6,7 @@ from typing import (
)
_Decimal = Union[Decimal, int]
_ComparableNum = Union[Decimal, int, float]
BasicContext = ... # type: Context
DefaultContext = ... # type: Context
@@ -201,12 +202,12 @@ class Decimal(SupportsInt, SupportsFloat, SupportsAbs[Decimal], SupportsRound[in
def __floor__(self) -> int: ...
def __floordiv__(self, other: _Decimal) -> Decimal: ...
def __format__(self, specifier, context=..., _localeconv=...) -> str: ...
def __ge__(self, other: _Decimal) -> bool: ...
def __gt__(self, other: _Decimal) -> bool: ...
def __ge__(self, other: _ComparableNum) -> bool: ...
def __gt__(self, other: _ComparableNum) -> bool: ...
def __hash__(self) -> int: ...
def __int__(self) -> int: ...
def __le__(self, other: _Decimal) -> bool: ...
def __lt__(self, other: _Decimal) -> bool: ...
def __le__(self, other: _ComparableNum) -> bool: ...
def __lt__(self, other: _ComparableNum) -> bool: ...
def __mod__(self, other: _Decimal) -> Decimal: ...
def __mul__(self, other: _Decimal) -> Decimal: ...
def __ne__(self, other: object) -> bool: ...