From d01b052dadff51d5a8d36ca9298d6f885740a492 Mon Sep 17 00:00:00 2001 From: Semyon Moroz Date: Mon, 12 May 2025 05:23:21 +0000 Subject: [PATCH] Bump `decimal` to 3.14 (#14017) Co-authored-by: Jelle Zijlstra --- stdlib/@tests/stubtest_allowlists/py314.txt | 5 ----- stdlib/_decimal.pyi | 5 +++++ stdlib/_pydecimal.pyi | 4 ++++ stdlib/decimal.pyi | 8 ++++++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/py314.txt b/stdlib/@tests/stubtest_allowlists/py314.txt index 67a725257..342b90283 100644 --- a/stdlib/@tests/stubtest_allowlists/py314.txt +++ b/stdlib/@tests/stubtest_allowlists/py314.txt @@ -8,9 +8,6 @@ _asyncio.future_discard_from_awaited_by _ctypes.POINTER _ctypes.byref _ctypes.pointer -_decimal.Decimal.from_number -_decimal.IEEEContext -_decimal.IEEE_CONTEXT_MAX_BITS _heapq.heapify_max _heapq.heappop_max _heapq.heappush_max @@ -103,8 +100,6 @@ dataclasses.Field.__init__ dataclasses.Field.doc dataclasses.field dataclasses.make_dataclass -decimal.Decimal.from_number -decimal.IEEE_CONTEXT_MAX_BITS dis.Instruction.make enum.Enum.__signature__ enum.EnumMeta.__signature__ diff --git a/stdlib/_decimal.pyi b/stdlib/_decimal.pyi index 06c0197dc..fd0e6e6ac 100644 --- a/stdlib/_decimal.pyi +++ b/stdlib/_decimal.pyi @@ -41,6 +41,8 @@ MAX_EMAX: Final[int] MAX_PREC: Final[int] MIN_EMIN: Final[int] MIN_ETINY: Final[int] +if sys.version_info >= (3, 14): + IEEE_CONTEXT_MAX_BITS: Final[int] def setcontext(context: Context, /) -> None: ... def getcontext() -> Context: ... @@ -62,6 +64,9 @@ if sys.version_info >= (3, 11): else: def localcontext(ctx: Context | None = None) -> _ContextManager: ... +if sys.version_info >= (3, 14): + def IEEEContext(bits: int, /) -> Context: ... + DefaultContext: Context BasicContext: Context ExtendedContext: Context diff --git a/stdlib/_pydecimal.pyi b/stdlib/_pydecimal.pyi index faff626ac..a6723f749 100644 --- a/stdlib/_pydecimal.pyi +++ b/stdlib/_pydecimal.pyi @@ -1,5 +1,6 @@ # This is a slight lie, the implementations aren't exactly identical # However, in all likelihood, the differences are inconsequential +import sys from _decimal import * __all__ = [ @@ -41,3 +42,6 @@ __all__ = [ "HAVE_THREADS", "HAVE_CONTEXTVAR", ] + +if sys.version_info >= (3, 14): + __all__ += ["IEEEContext", "IEEE_CONTEXT_MAX_BITS"] diff --git a/stdlib/decimal.pyi b/stdlib/decimal.pyi index 4ded21e0b..b85c00080 100644 --- a/stdlib/decimal.pyi +++ b/stdlib/decimal.pyi @@ -1,4 +1,5 @@ import numbers +import sys from _decimal import ( HAVE_CONTEXTVAR as HAVE_CONTEXTVAR, HAVE_THREADS as HAVE_THREADS, @@ -28,6 +29,9 @@ from types import TracebackType from typing import Any, ClassVar, Literal, NamedTuple, final, overload, type_check_only from typing_extensions import Self, TypeAlias +if sys.version_info >= (3, 14): + from _decimal import IEEE_CONTEXT_MAX_BITS as IEEE_CONTEXT_MAX_BITS, IEEEContext as IEEEContext + _Decimal: TypeAlias = Decimal | int _DecimalNew: TypeAlias = Decimal | float | str | tuple[int, Sequence[int], int] _ComparableNum: TypeAlias = Decimal | float | numbers.Rational @@ -66,6 +70,10 @@ class FloatOperation(DecimalException, TypeError): ... class Decimal: def __new__(cls, value: _DecimalNew = "0", context: Context | None = None) -> Self: ... + if sys.version_info >= (3, 14): + @classmethod + def from_number(cls, number: Decimal | float, /) -> Self: ... + @classmethod def from_float(cls, f: float, /) -> Self: ... def __bool__(self) -> bool: ...