1
- import numbers
2
1
import sys
3
- from collections .abc import Container , Sequence
2
+ from decimal import (
3
+ Clamped as Clamped ,
4
+ Context as Context ,
5
+ ConversionSyntax as ConversionSyntax ,
6
+ Decimal as Decimal ,
7
+ DecimalException as DecimalException ,
8
+ DecimalTuple as DecimalTuple ,
9
+ DivisionByZero as DivisionByZero ,
10
+ DivisionImpossible as DivisionImpossible ,
11
+ DivisionUndefined as DivisionUndefined ,
12
+ FloatOperation as FloatOperation ,
13
+ Inexact as Inexact ,
14
+ InvalidContext as InvalidContext ,
15
+ InvalidOperation as InvalidOperation ,
16
+ Overflow as Overflow ,
17
+ Rounded as Rounded ,
18
+ Subnormal as Subnormal ,
19
+ Underflow as Underflow ,
20
+ )
4
21
from types import TracebackType
5
- from typing import Any , ClassVar , Final , Literal , NamedTuple , overload
6
- from typing_extensions import Self , TypeAlias
22
+ from typing import Final
23
+ from typing_extensions import TypeAlias
7
24
8
- _Decimal : TypeAlias = Decimal | int
9
- _DecimalNew : TypeAlias = Decimal | float | str | tuple [int , Sequence [int ], int ]
10
- _ComparableNum : TypeAlias = Decimal | float | numbers .Rational
25
+ _TrapType : TypeAlias = type [DecimalException ]
26
+
27
+ class _ContextManager :
28
+ new_context : Context
29
+ saved_context : Context
30
+ def __init__ (self , new_context : Context ) -> None : ...
31
+ def __enter__ (self ) -> Context : ...
32
+ def __exit__ (self , t : type [BaseException ] | None , v : BaseException | None , tb : TracebackType | None ) -> None : ...
11
33
12
34
__version__ : Final [str ]
13
35
__libmpdec_version__ : Final [str ]
14
36
15
- class DecimalTuple (NamedTuple ):
16
- sign : int
17
- digits : tuple [int , ...]
18
- exponent : int | Literal ["n" , "N" , "F" ]
19
-
20
37
ROUND_DOWN : Final [str ]
21
38
ROUND_HALF_UP : Final [str ]
22
39
ROUND_HALF_EVEN : Final [str ]
@@ -32,21 +49,6 @@ MAX_PREC: Final[int]
32
49
MIN_EMIN : Final [int ]
33
50
MIN_ETINY : Final [int ]
34
51
35
- class DecimalException (ArithmeticError ): ...
36
- class Clamped (DecimalException ): ...
37
- class InvalidOperation (DecimalException ): ...
38
- class ConversionSyntax (InvalidOperation ): ...
39
- class DivisionByZero (DecimalException , ZeroDivisionError ): ...
40
- class DivisionImpossible (InvalidOperation ): ...
41
- class DivisionUndefined (InvalidOperation , ZeroDivisionError ): ...
42
- class Inexact (DecimalException ): ...
43
- class InvalidContext (InvalidOperation ): ...
44
- class Rounded (DecimalException ): ...
45
- class Subnormal (DecimalException ): ...
46
- class Overflow (Inexact , Rounded ): ...
47
- class Underflow (Inexact , Rounded , Subnormal ): ...
48
- class FloatOperation (DecimalException , TypeError ): ...
49
-
50
52
def setcontext (context : Context , / ) -> None : ...
51
53
def getcontext () -> Context : ...
52
54
@@ -67,215 +69,6 @@ if sys.version_info >= (3, 11):
67
69
else :
68
70
def localcontext (ctx : Context | None = None ) -> _ContextManager : ...
69
71
70
- class Decimal :
71
- def __new__ (cls , value : _DecimalNew = ..., context : Context | None = ...) -> Self : ...
72
- @classmethod
73
- def from_float (cls , f : float , / ) -> Self : ...
74
- def __bool__ (self ) -> bool : ...
75
- def compare (self , other : _Decimal , context : Context | None = None ) -> Decimal : ...
76
- def __hash__ (self ) -> int : ...
77
- def as_tuple (self ) -> DecimalTuple : ...
78
- def as_integer_ratio (self ) -> tuple [int , int ]: ...
79
- def to_eng_string (self , context : Context | None = None ) -> str : ...
80
- def __abs__ (self ) -> Decimal : ...
81
- def __add__ (self , value : _Decimal , / ) -> Decimal : ...
82
- def __divmod__ (self , value : _Decimal , / ) -> tuple [Decimal , Decimal ]: ...
83
- def __eq__ (self , value : object , / ) -> bool : ...
84
- def __floordiv__ (self , value : _Decimal , / ) -> Decimal : ...
85
- def __ge__ (self , value : _ComparableNum , / ) -> bool : ...
86
- def __gt__ (self , value : _ComparableNum , / ) -> bool : ...
87
- def __le__ (self , value : _ComparableNum , / ) -> bool : ...
88
- def __lt__ (self , value : _ComparableNum , / ) -> bool : ...
89
- def __mod__ (self , value : _Decimal , / ) -> Decimal : ...
90
- def __mul__ (self , value : _Decimal , / ) -> Decimal : ...
91
- def __neg__ (self ) -> Decimal : ...
92
- def __pos__ (self ) -> Decimal : ...
93
- def __pow__ (self , value : _Decimal , mod : _Decimal | None = None , / ) -> Decimal : ...
94
- def __radd__ (self , value : _Decimal , / ) -> Decimal : ...
95
- def __rdivmod__ (self , value : _Decimal , / ) -> tuple [Decimal , Decimal ]: ...
96
- def __rfloordiv__ (self , value : _Decimal , / ) -> Decimal : ...
97
- def __rmod__ (self , value : _Decimal , / ) -> Decimal : ...
98
- def __rmul__ (self , value : _Decimal , / ) -> Decimal : ...
99
- def __rsub__ (self , value : _Decimal , / ) -> Decimal : ...
100
- def __rtruediv__ (self , value : _Decimal , / ) -> Decimal : ...
101
- def __sub__ (self , value : _Decimal , / ) -> Decimal : ...
102
- def __truediv__ (self , value : _Decimal , / ) -> Decimal : ...
103
- def remainder_near (self , other : _Decimal , context : Context | None = None ) -> Decimal : ...
104
- def __float__ (self ) -> float : ...
105
- def __int__ (self ) -> int : ...
106
- def __trunc__ (self ) -> int : ...
107
- @property
108
- def real (self ) -> Decimal : ...
109
- @property
110
- def imag (self ) -> Decimal : ...
111
- def conjugate (self ) -> Decimal : ...
112
- def __complex__ (self ) -> complex : ...
113
- @overload
114
- def __round__ (self ) -> int : ...
115
- @overload
116
- def __round__ (self , ndigits : int , / ) -> Decimal : ...
117
- def __floor__ (self ) -> int : ...
118
- def __ceil__ (self ) -> int : ...
119
- def fma (self , other : _Decimal , third : _Decimal , context : Context | None = None ) -> Decimal : ...
120
- def __rpow__ (self , value : _Decimal , mod : Context | None = None , / ) -> Decimal : ...
121
- def normalize (self , context : Context | None = None ) -> Decimal : ...
122
- def quantize (self , exp : _Decimal , rounding : str | None = None , context : Context | None = None ) -> Decimal : ...
123
- def same_quantum (self , other : _Decimal , context : Context | None = None ) -> bool : ...
124
- def to_integral_exact (self , rounding : str | None = None , context : Context | None = None ) -> Decimal : ...
125
- def to_integral_value (self , rounding : str | None = None , context : Context | None = None ) -> Decimal : ...
126
- def to_integral (self , rounding : str | None = None , context : Context | None = None ) -> Decimal : ...
127
- def sqrt (self , context : Context | None = None ) -> Decimal : ...
128
- def max (self , other : _Decimal , context : Context | None = None ) -> Decimal : ...
129
- def min (self , other : _Decimal , context : Context | None = None ) -> Decimal : ...
130
- def adjusted (self ) -> int : ...
131
- def canonical (self ) -> Decimal : ...
132
- def compare_signal (self , other : _Decimal , context : Context | None = None ) -> Decimal : ...
133
- def compare_total (self , other : _Decimal , context : Context | None = None ) -> Decimal : ...
134
- def compare_total_mag (self , other : _Decimal , context : Context | None = None ) -> Decimal : ...
135
- def copy_abs (self ) -> Decimal : ...
136
- def copy_negate (self ) -> Decimal : ...
137
- def copy_sign (self , other : _Decimal , context : Context | None = None ) -> Decimal : ...
138
- def exp (self , context : Context | None = None ) -> Decimal : ...
139
- def is_canonical (self ) -> bool : ...
140
- def is_finite (self ) -> bool : ...
141
- def is_infinite (self ) -> bool : ...
142
- def is_nan (self ) -> bool : ...
143
- def is_normal (self , context : Context | None = None ) -> bool : ...
144
- def is_qnan (self ) -> bool : ...
145
- def is_signed (self ) -> bool : ...
146
- def is_snan (self ) -> bool : ...
147
- def is_subnormal (self , context : Context | None = None ) -> bool : ...
148
- def is_zero (self ) -> bool : ...
149
- def ln (self , context : Context | None = None ) -> Decimal : ...
150
- def log10 (self , context : Context | None = None ) -> Decimal : ...
151
- def logb (self , context : Context | None = None ) -> Decimal : ...
152
- def logical_and (self , other : _Decimal , context : Context | None = None ) -> Decimal : ...
153
- def logical_invert (self , context : Context | None = None ) -> Decimal : ...
154
- def logical_or (self , other : _Decimal , context : Context | None = None ) -> Decimal : ...
155
- def logical_xor (self , other : _Decimal , context : Context | None = None ) -> Decimal : ...
156
- def max_mag (self , other : _Decimal , context : Context | None = None ) -> Decimal : ...
157
- def min_mag (self , other : _Decimal , context : Context | None = None ) -> Decimal : ...
158
- def next_minus (self , context : Context | None = None ) -> Decimal : ...
159
- def next_plus (self , context : Context | None = None ) -> Decimal : ...
160
- def next_toward (self , other : _Decimal , context : Context | None = None ) -> Decimal : ...
161
- def number_class (self , context : Context | None = None ) -> str : ...
162
- def radix (self ) -> Decimal : ...
163
- def rotate (self , other : _Decimal , context : Context | None = None ) -> Decimal : ...
164
- def scaleb (self , other : _Decimal , context : Context | None = None ) -> Decimal : ...
165
- def shift (self , other : _Decimal , context : Context | None = None ) -> Decimal : ...
166
- def __reduce__ (self ) -> tuple [type [Self ], tuple [str ]]: ...
167
- def __copy__ (self ) -> Self : ...
168
- def __deepcopy__ (self , memo : Any , / ) -> Self : ...
169
- def __format__ (self , specifier : str , context : Context | None = ..., / ) -> str : ...
170
-
171
- class _ContextManager :
172
- new_context : Context
173
- saved_context : Context
174
- def __init__ (self , new_context : Context ) -> None : ...
175
- def __enter__ (self ) -> Context : ...
176
- def __exit__ (self , t : type [BaseException ] | None , v : BaseException | None , tb : TracebackType | None ) -> None : ...
177
-
178
- _TrapType : TypeAlias = type [DecimalException ]
179
-
180
- class Context :
181
- # TODO: Context doesn't allow you to delete *any* attributes from instances of the class at runtime,
182
- # even settable attributes like `prec` and `rounding`,
183
- # but that's inexpressable in the stub.
184
- # Type checkers either ignore it or misinterpret it
185
- # if you add a `def __delattr__(self, name: str, /) -> NoReturn` method to the stub
186
- prec : int
187
- rounding : str
188
- Emin : int
189
- Emax : int
190
- capitals : int
191
- clamp : int
192
- traps : dict [_TrapType , bool ]
193
- flags : dict [_TrapType , bool ]
194
- def __init__ (
195
- self ,
196
- prec : int | None = ...,
197
- rounding : str | None = ...,
198
- Emin : int | None = ...,
199
- Emax : int | None = ...,
200
- capitals : int | None = ...,
201
- clamp : int | None = ...,
202
- flags : None | dict [_TrapType , bool ] | Container [_TrapType ] = ...,
203
- traps : None | dict [_TrapType , bool ] | Container [_TrapType ] = ...,
204
- _ignored_flags : list [_TrapType ] | None = ...,
205
- ) -> None : ...
206
- def __reduce__ (self ) -> tuple [type [Self ], tuple [Any , ...]]: ...
207
- def clear_flags (self ) -> None : ...
208
- def clear_traps (self ) -> None : ...
209
- def copy (self ) -> Context : ...
210
- def __copy__ (self ) -> Context : ...
211
- # see https://github.com/python/cpython/issues/94107
212
- __hash__ : ClassVar [None ] # type: ignore[assignment]
213
- def Etiny (self ) -> int : ...
214
- def Etop (self ) -> int : ...
215
- def create_decimal (self , num : _DecimalNew = "0" , / ) -> Decimal : ...
216
- def create_decimal_from_float (self , f : float , / ) -> Decimal : ...
217
- def abs (self , x : _Decimal , / ) -> Decimal : ...
218
- def add (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
219
- def canonical (self , x : Decimal , / ) -> Decimal : ...
220
- def compare (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
221
- def compare_signal (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
222
- def compare_total (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
223
- def compare_total_mag (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
224
- def copy_abs (self , x : _Decimal , / ) -> Decimal : ...
225
- def copy_decimal (self , x : _Decimal , / ) -> Decimal : ...
226
- def copy_negate (self , x : _Decimal , / ) -> Decimal : ...
227
- def copy_sign (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
228
- def divide (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
229
- def divide_int (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
230
- def divmod (self , x : _Decimal , y : _Decimal , / ) -> tuple [Decimal , Decimal ]: ...
231
- def exp (self , x : _Decimal , / ) -> Decimal : ...
232
- def fma (self , x : _Decimal , y : _Decimal , z : _Decimal , / ) -> Decimal : ...
233
- def is_canonical (self , x : _Decimal , / ) -> bool : ...
234
- def is_finite (self , x : _Decimal , / ) -> bool : ...
235
- def is_infinite (self , x : _Decimal , / ) -> bool : ...
236
- def is_nan (self , x : _Decimal , / ) -> bool : ...
237
- def is_normal (self , x : _Decimal , / ) -> bool : ...
238
- def is_qnan (self , x : _Decimal , / ) -> bool : ...
239
- def is_signed (self , x : _Decimal , / ) -> bool : ...
240
- def is_snan (self , x : _Decimal , / ) -> bool : ...
241
- def is_subnormal (self , x : _Decimal , / ) -> bool : ...
242
- def is_zero (self , x : _Decimal , / ) -> bool : ...
243
- def ln (self , x : _Decimal , / ) -> Decimal : ...
244
- def log10 (self , x : _Decimal , / ) -> Decimal : ...
245
- def logb (self , x : _Decimal , / ) -> Decimal : ...
246
- def logical_and (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
247
- def logical_invert (self , x : _Decimal , / ) -> Decimal : ...
248
- def logical_or (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
249
- def logical_xor (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
250
- def max (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
251
- def max_mag (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
252
- def min (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
253
- def min_mag (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
254
- def minus (self , x : _Decimal , / ) -> Decimal : ...
255
- def multiply (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
256
- def next_minus (self , x : _Decimal , / ) -> Decimal : ...
257
- def next_plus (self , x : _Decimal , / ) -> Decimal : ...
258
- def next_toward (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
259
- def normalize (self , x : _Decimal , / ) -> Decimal : ...
260
- def number_class (self , x : _Decimal , / ) -> str : ...
261
- def plus (self , x : _Decimal , / ) -> Decimal : ...
262
- def power (self , a : _Decimal , b : _Decimal , modulo : _Decimal | None = None ) -> Decimal : ...
263
- def quantize (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
264
- def radix (self ) -> Decimal : ...
265
- def remainder (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
266
- def remainder_near (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
267
- def rotate (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
268
- def same_quantum (self , x : _Decimal , y : _Decimal , / ) -> bool : ...
269
- def scaleb (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
270
- def shift (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
271
- def sqrt (self , x : _Decimal , / ) -> Decimal : ...
272
- def subtract (self , x : _Decimal , y : _Decimal , / ) -> Decimal : ...
273
- def to_eng_string (self , x : _Decimal , / ) -> str : ...
274
- def to_sci_string (self , x : _Decimal , / ) -> str : ...
275
- def to_integral_exact (self , x : _Decimal , / ) -> Decimal : ...
276
- def to_integral_value (self , x : _Decimal , / ) -> Decimal : ...
277
- def to_integral (self , x : _Decimal , / ) -> Decimal : ...
278
-
279
72
DefaultContext : Context
280
73
BasicContext : Context
281
74
ExtendedContext : Context
0 commit comments