Skip to content

Commit

Permalink
Add _pydecimal and _decimal stubs (python#4003)
Browse files Browse the repository at this point in the history
  • Loading branch information
CraftSpider authored and Vishal Kuo committed Jun 26, 2020
1 parent 3546f4b commit 6ecce68
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
9 changes: 5 additions & 4 deletions stdlib/2and3/decimal.pyi
Expand Up @@ -35,7 +35,8 @@ if sys.version_info >= (3,):
MIN_ETINY: int

class DecimalException(ArithmeticError):
def handle(self, context: Context, *args: Any) -> Optional[Decimal]: ...
if sys.version_info < (3,):
def handle(self, context: Context, *args: Any) -> Optional[Decimal]: ...

class Clamped(DecimalException): ...

Expand Down Expand Up @@ -64,14 +65,14 @@ class Underflow(Inexact, Rounded, Subnormal): ...
if sys.version_info >= (3,):
class FloatOperation(DecimalException, TypeError): ...

def setcontext(context: Context) -> None: ...
def setcontext(__context: Context) -> None: ...
def getcontext() -> Context: ...
def localcontext(ctx: Optional[Context] = ...) -> _ContextManager: ...

class Decimal(object):
def __new__(cls: Type[_DecimalT], value: _DecimalNew = ..., context: Optional[Context] = ...) -> _DecimalT: ...
@classmethod
def from_float(cls, f: float) -> Decimal: ...
def from_float(cls, __f: float) -> Decimal: ...
if sys.version_info >= (3,):
def __bool__(self) -> bool: ...
else:
Expand All @@ -83,7 +84,7 @@ class Decimal(object):
def compare(self, other: _Decimal, context: Optional[Context] = ...) -> Decimal: ...
def __hash__(self) -> int: ...
def as_tuple(self) -> DecimalTuple: ...
if sys.version_info >= (3,):
if sys.version_info >= (3, 6):
def as_integer_ratio(self) -> Tuple[int, int]: ...

def to_eng_string(self, context: Optional[Context] = ...) -> str: ...
Expand Down
2 changes: 2 additions & 0 deletions stdlib/3/_decimal.pyi
@@ -0,0 +1,2 @@

from decimal import *
4 changes: 4 additions & 0 deletions stdlib/3/_pydecimal.pyi
@@ -0,0 +1,4 @@

# This is a slight lie, the implementations aren't exactly identical
# However, in all likelihood, the differences are inconsequential
from decimal import *
1 change: 0 additions & 1 deletion tests/stubtest_whitelists/py35.txt
Expand Up @@ -21,7 +21,6 @@ codecs.StreamRecoder.seek
collections.Reversible
collections.UserString.maketrans
ctypes.CDLL.__init__
decimal.Decimal.as_integer_ratio
fractions.Fraction.__new__ # private _normalize param was made keyword-only in Python 3.6
gettext.NullTranslations.npgettext
gettext.NullTranslations.pgettext
Expand Down
2 changes: 0 additions & 2 deletions tests/stubtest_whitelists/py38.txt
Expand Up @@ -66,8 +66,6 @@ copy.PyStringMap
dataclasses.dataclass
dataclasses.field
dataclasses.replace
decimal.Decimal.from_float
decimal.setcontext
email.message.MIMEPart.as_string
enum.Enum._generate_next_value_
functools.partialmethod.__get__
Expand Down
2 changes: 1 addition & 1 deletion tests/stubtest_whitelists/py3_common.txt
Expand Up @@ -154,7 +154,6 @@ curses.COLS
curses.LINES
dbm.error
dbm.ndbm
decimal.DecimalException.handle
difflib.SequenceMatcher.__init__
distutils.archive_util.make_archive
distutils.archive_util.make_tarball
Expand Down Expand Up @@ -523,6 +522,7 @@ zlib.compressobj
# ==========
# Whitelist entries that cannot or should not be fixed
# ==========
_pydecimal.* # See comments in file
ast.NodeVisitor.visit_\w+ # Methods are discovered dynamically, see #3796
# Weird special builtins that are typed as functions, but aren't functions
builtins.copyright
Expand Down

0 comments on commit 6ecce68

Please sign in to comment.