-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refine stubs for Python 2's decimal module #545
Merged
gvanrossum
merged 2 commits into
python:master
from
Michael0x2a:refine-python2-decimal-stubs
Sep 14, 2016
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
# Stubs for decimal (Python 2) | ||
# | ||
# NOTE: This dynamically typed stub was automatically generated by stubgen. | ||
|
||
from typing import Any, SupportsAbs, SupportsFloat, SupportsInt | ||
from typing import ( | ||
Any, Dict, NamedTuple, Optional, Sequence, Tuple, Union, | ||
SupportsAbs, SupportsFloat, SupportsInt, | ||
) | ||
|
||
ROUND_DOWN = ... # type: Any | ||
ROUND_HALF_UP = ... # type: Any | ||
ROUND_HALF_EVEN = ... # type: Any | ||
ROUND_CEILING = ... # type: Any | ||
ROUND_FLOOR = ... # type: Any | ||
ROUND_UP = ... # type: Any | ||
ROUND_HALF_DOWN = ... # type: Any | ||
ROUND_05UP = ... # type: Any | ||
_Decimal = Union[Decimal, int] | ||
|
||
DecimalTuple = NamedTuple('DecimalTuple', | ||
[('sign', int), | ||
('digits', Sequence[int]), # TODO: Use Tuple[int, ...] | ||
('exponent', int)]) | ||
|
||
ROUND_DOWN = ... # type: str | ||
ROUND_HALF_UP = ... # type: str | ||
ROUND_HALF_EVEN = ... # type: str | ||
ROUND_CEILING = ... # type: str | ||
ROUND_FLOOR = ... # type: str | ||
ROUND_UP = ... # type: str | ||
ROUND_HALF_DOWN = ... # type: str | ||
ROUND_05UP = ... # type: str | ||
|
||
class DecimalException(ArithmeticError): | ||
def handle(self, context, *args): ... | ||
|
@@ -40,120 +48,125 @@ class Overflow(Inexact, Rounded): ... | |
|
||
class Underflow(Inexact, Rounded, Subnormal): ... | ||
|
||
def setcontext(context): ... | ||
def getcontext(): ... | ||
def localcontext(ctx=None): ... | ||
def setcontext(context: Context): ... | ||
def getcontext() -> Context: ... | ||
def localcontext(ctx: Optional[Context] = None) -> _ContextManager: ... | ||
|
||
class Decimal(SupportsAbs[Decimal], SupportsFloat, SupportsInt): | ||
def __new__(cls, value=..., context=None): ... | ||
def __init__(cls, value: Union[_Decimal, float, str, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also allow Number here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NM, I think this a problem on our side. |
||
Tuple[int, Sequence[int], int]] = ..., | ||
context: Context = ...) -> None: ... | ||
@classmethod | ||
def from_float(cls, f): ... | ||
def __nonzero__(self): ... | ||
def __eq__(self, other, context=None): ... | ||
def __ne__(self, other, context=None): ... | ||
def __lt__(self, other, context=None): ... | ||
def __le__(self, other, context=None): ... | ||
def __gt__(self, other, context=None): ... | ||
def __ge__(self, other, context=None): ... | ||
def compare(self, other, context=None): ... | ||
def __hash__(self): ... | ||
def as_tuple(self): ... | ||
def to_eng_string(self, context=None): ... | ||
def __neg__(self, context=None): ... | ||
def __pos__(self, context=None): ... | ||
def __abs__(self, round=True, context=None): ... | ||
def __add__(self, other, context=None): ... | ||
def __radd__(self, other, context=None): ... | ||
def __sub__(self, other, context=None): ... | ||
def __rsub__(self, other, context=None): ... | ||
def __mul__(self, other, context=None): ... | ||
def __rmul__(self, other, context=None): ... | ||
def __truediv__(self, other, context=None): ... | ||
def __rtruediv__(self, other, context=None): ... | ||
def __div__(self, other, context=None): ... | ||
def __rdiv__(self, other, context=None): ... | ||
def __divmod__(self, other, context=None): ... | ||
def __rdivmod__(self, other, context=None): ... | ||
def __mod__(self, other, context=None): ... | ||
def __rmod__(self, other, context=None): ... | ||
def remainder_near(self, other, context=None): ... | ||
def __floordiv__(self, other, context=None): ... | ||
def __rfloordiv__(self, other, context=None): ... | ||
def __float__(self): ... | ||
def __int__(self): ... | ||
def __trunc__(self): ... | ||
real = ... # type: property | ||
imag = ... # type: property | ||
def conjugate(self): ... | ||
def __complex__(self): ... | ||
def __long__(self): ... | ||
def fma(self, other, third, context=None): ... | ||
def __pow__(self, other, modulo=None, context=None): ... | ||
def __rpow__(self, other, context=None): ... | ||
def normalize(self, context=None): ... | ||
def quantize(self, exp, rounding=None, context=None, watchexp=True): ... | ||
def same_quantum(self, other): ... | ||
def to_integral_exact(self, rounding=None, context=None): ... | ||
def to_integral_value(self, rounding=None, context=None): ... | ||
def to_integral(self, rounding=None, context=None): ... | ||
def sqrt(self, context=None): ... | ||
def max(self, other, context=None): ... | ||
def min(self, other, context=None): ... | ||
def adjusted(self): ... | ||
def canonical(self, context=None): ... | ||
def compare_signal(self, other, context=None): ... | ||
def compare_total(self, other): ... | ||
def compare_total_mag(self, other): ... | ||
def copy_abs(self): ... | ||
def copy_negate(self): ... | ||
def copy_sign(self, other): ... | ||
def exp(self, context=None): ... | ||
def is_canonical(self): ... | ||
def is_finite(self): ... | ||
def is_infinite(self): ... | ||
def is_nan(self): ... | ||
def is_normal(self, context=None): ... | ||
def is_qnan(self): ... | ||
def is_signed(self): ... | ||
def is_snan(self): ... | ||
def is_subnormal(self, context=None): ... | ||
def is_zero(self): ... | ||
def ln(self, context=None): ... | ||
def log10(self, context=None): ... | ||
def logb(self, context=None): ... | ||
def logical_and(self, other, context=None): ... | ||
def logical_invert(self, context=None): ... | ||
def logical_or(self, other, context=None): ... | ||
def logical_xor(self, other, context=None): ... | ||
def max_mag(self, other, context=None): ... | ||
def min_mag(self, other, context=None): ... | ||
def next_minus(self, context=None): ... | ||
def next_plus(self, context=None): ... | ||
def next_toward(self, other, context=None): ... | ||
def number_class(self, context=None): ... | ||
def radix(self): ... | ||
def rotate(self, other, context=None): ... | ||
def scaleb(self, other, context=None): ... | ||
def shift(self, other, context=None): ... | ||
def from_float(cls, f: float) -> Decimal: ... | ||
def __nonzero__(self) -> bool: ... | ||
def __eq__(self, other: object) -> bool: ... | ||
def __ne__(self, other: object) -> bool: ... | ||
def __lt__(self, other: _Decimal) -> bool: ... | ||
def __le__(self, other: _Decimal) -> bool: ... | ||
def __gt__(self, other: _Decimal) -> bool: ... | ||
def __ge__(self, other: _Decimal) -> bool: ... | ||
def compare(self, other: _Decimal) -> int: ... | ||
def __hash__(self) -> int: ... | ||
def as_tuple(self) -> DecimalTuple: ... | ||
def to_eng_string(self, context: Context = ...) -> str: ... | ||
def __neg__(self) -> Decimal: ... | ||
def __pos__(self) -> Decimal: ... | ||
def __abs__(self, round: bool = True) -> Decimal: ... | ||
def __add__(self, other: _Decimal) -> Decimal: ... | ||
def __radd__(self, other: int) -> Decimal: ... | ||
def __sub__(self, other: _Decimal) -> Decimal: ... | ||
def __rsub__(self, other: int) -> Decimal: ... | ||
def __mul__(self, other: _Decimal) -> Decimal: ... | ||
def __rmul__(self, other: int) -> Decimal: ... | ||
def __truediv__(self, other: _Decimal) -> Decimal: ... | ||
def __rtruediv__(self, other: int) -> Decimal: ... | ||
def __div__(self, other: _Decimal) -> Decimal: ... | ||
def __rdiv__(self, other: int) -> Decimal: ... | ||
def __divmod__(self, other: _Decimal) -> Tuple[Decimal, Decimal]: ... | ||
def __rdivmod__(self, other: int) -> Tuple[Decimal, Decimal]: ... | ||
def __mod__(self, other: _Decimal) -> Decimal: ... | ||
def __rmod__(self, other: int) -> Decimal: ... | ||
def remainder_near(self, other: _Decimal, context: Context = ...) -> Decimal: ... | ||
def __floordiv__(self, other: _Decimal) -> Decimal: ... | ||
def __rfloordiv__(self, other: int) -> Decimal: ... | ||
def __float__(self) -> float: ... | ||
def __int__(self) -> int: ... | ||
def __trunc__(self) -> int: ... | ||
@property | ||
def imag(self) -> Decimal: ... | ||
@property | ||
def real(self) -> Decimal: ... | ||
def conjugate(self) -> Decimal: ... | ||
def __complex__(self) -> complex: ... | ||
def __long__(self) -> long: ... | ||
def fma(self, other: _Decimal, third: _Decimal, context: Context = ...) -> Decimal: ... | ||
def __pow__(self, other: _Decimal) -> Decimal: ... | ||
def __rpow__(self, other: int) -> Decimal: ... | ||
def normalize(self, context: Context = ...) -> Decimal: ... | ||
def quantize(self, exp: _Decimal, rounding: str = ..., | ||
context: Context = ...) -> Decimal: ... | ||
def same_quantum(self, other: Decimal) -> bool: ... | ||
def to_integral(self, rounding: str = ..., context: Context = ...) -> Decimal: ... | ||
def to_integral_exact(self, rounding: str = ..., context: Context = ...) -> Decimal: ... | ||
def to_integral_value(self, rounding: str = ..., context: Context = ...) -> Decimal: ... | ||
def sqrt(self, context: Context = ...) -> Decimal: ... | ||
def max(self, other: _Decimal, context: Context = ...) -> Decimal: ... | ||
def min(self, other: _Decimal, context: Context = ...) -> Decimal: ... | ||
def adjusted(self) -> int: ... | ||
def canonical(self, context: Context = ...) -> Decimal: ... | ||
def compare_signal(self, other: _Decimal, context: Context = ...) -> Decimal: ... | ||
def compare_total(self, other: _Decimal) -> Decimal: ... | ||
def compare_total_mag(self, other: _Decimal) -> Decimal: ... | ||
def copy_abs(self) -> Decimal: ... | ||
def copy_negate(self) -> Decimal: ... | ||
def copy_sign(self, other: _Decimal) -> Decimal: ... | ||
def exp(self, context: Context = ...) -> Decimal: ... | ||
def is_canonical(self) -> bool: ... | ||
def is_finite(self) -> bool: ... | ||
def is_infinite(self) -> bool: ... | ||
def is_nan(self) -> bool: ... | ||
def is_normal(self, context: Context = ...) -> bool: ... | ||
def is_qnan(self) -> bool: ... | ||
def is_signed(self) -> bool: ... | ||
def is_snan(self) -> bool: ... | ||
def is_subnormal(self, context: Context = ...) -> bool: ... | ||
def is_zero(self) -> bool: ... | ||
def ln(self, context: Context = ...) -> Decimal: ... | ||
def log10(self, context: Context = ...) -> Decimal: ... | ||
def logb(self, context: Context = ...) -> Decimal: ... | ||
def logical_and(self, other: _Decimal, context: Context = ...) -> Decimal: ... | ||
def logical_invert(self, context: Context = ...) -> Decimal: ... | ||
def logical_or(self, other: _Decimal, context: Context = ...) -> Decimal: ... | ||
def logical_xor(self, other: _Decimal, context: Context = ...) -> Decimal: ... | ||
def max_mag(self, other: _Decimal, context: Context = ...) -> Decimal: ... | ||
def min_mag(self, other: _Decimal, context: Context = ...) -> Decimal: ... | ||
def next_minus(self, context: Context = ...) -> Decimal: ... | ||
def next_plus(self, context: Context = ...) -> Decimal: ... | ||
def next_toward(self, other: _Decimal, context: Context = ...) -> Decimal: ... | ||
def number_class(self, context: Context = ...) -> str: ... | ||
def radix(self) -> Decimal: ... | ||
def rotate(self, other: _Decimal, context: Context = ...) -> Decimal: ... | ||
def scaleb(self, other: _Decimal, context: Context = ...) -> Decimal: ... | ||
def shift(self, other: _Decimal, context: Context = ...) -> Decimal: ... | ||
def __reduce__(self): ... | ||
def __copy__(self): ... | ||
def __deepcopy__(self, memo): ... | ||
def __format__(self, specifier, context=None, _localeconv=None): ... | ||
def __format__(self, specifier, context=None, _localeconv=None) -> str: ... | ||
|
||
class _ContextManager: | ||
new_context = ... # type: Any | ||
def __init__(self, new_context): ... | ||
saved_context = ... # type: Any | ||
new_context = ... # type: Context | ||
saved_context = ... # type: Context | ||
def __init__(self, new_context: Context) -> None: ... | ||
def __enter__(self): ... | ||
def __exit__(self, t, v, tb): ... | ||
|
||
class Context: | ||
prec = ... # type: Any | ||
rounding = ... # type: Any | ||
Emin = ... # type: Any | ||
Emax = ... # type: Any | ||
capitals = ... # type: Any | ||
traps = ... # type: Any | ||
prec = ... # type: int | ||
rounding = ... # type: str | ||
Emin = ... # type: int | ||
Emax = ... # type: int | ||
capitals = ... # type: int | ||
traps = ... # type: Dict[type, bool] | ||
flags = ... # type: Any | ||
def __init__(self, prec=None, rounding=None, traps=None, flags=None, Emin=None, Emax=None, capitals=None, _clamp=0, _ignored_flags=None): ... | ||
def clear_flags(self): ... | ||
|
@@ -226,6 +239,6 @@ class Context: | |
def to_integral_value(self, a): ... | ||
def to_integral(self, a): ... | ||
|
||
DefaultContext = ... # type: Any | ||
BasicContext = ... # type: Any | ||
ExtendedContext = ... # type: Any | ||
DefaultContext = ... # type: Context | ||
BasicContext = ... # type: Context | ||
ExtendedContext = ... # type: Context |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think modern Decimal is lenient about floats and just accepts them. I recommend just adding float here, else you have to add it to many other places (in our server code I found problems comparing floats to decimals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Should I also make that change in the Python 3's version of Decimal? (I copied
_Decimal
from the current Python 3 stubs).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, this needs more nuance. IIUC comparisons with floats are acceptable, but not e.g. addition. So maybe you need a more lenient union type just for comparisons.