@@ -1651,16 +1651,18 @@ _decimal_IEEEContext_impl(PyObject *module, Py_ssize_t bits)
1651
1651
/*[clinic input]
1652
1652
_decimal.Context.copy
1653
1653
1654
+ cls: defining_class
1655
+
1654
1656
Return a duplicate of the context with all flags cleared.
1655
1657
[clinic start generated code]*/
1656
1658
1657
1659
static PyObject *
1658
- _decimal_Context_copy_impl (PyObject * self )
1659
- /*[clinic end generated code: output=f99649a60a9c10f8 input=2589aa46b77cbc28 ]*/
1660
+ _decimal_Context_copy_impl (PyObject * self , PyTypeObject * cls )
1661
+ /*[clinic end generated code: output=31c9c8eeb0c0cf77 input=aef1c0bddabdf8f0 ]*/
1660
1662
{
1661
1663
PyObject * copy ;
1662
1664
1663
- decimal_state * state = get_module_state_from_ctx ( self );
1665
+ decimal_state * state = PyType_GetModuleState ( cls );
1664
1666
copy = PyObject_CallObject ((PyObject * )state -> PyDecContext_Type , NULL );
1665
1667
if (copy == NULL ) {
1666
1668
return NULL ;
@@ -1673,20 +1675,51 @@ _decimal_Context_copy_impl(PyObject *self)
1673
1675
return copy ;
1674
1676
}
1675
1677
1678
+ /*[clinic input]
1679
+ _decimal.Context.__copy__ = _decimal.Context.copy
1680
+
1681
+ [clinic start generated code]*/
1682
+
1683
+ static PyObject *
1684
+ _decimal_Context___copy___impl (PyObject * self , PyTypeObject * cls )
1685
+ /*[clinic end generated code: output=93552486e5fb0ab4 input=4a55dd22f6d31bcc]*/
1686
+ {
1687
+ return _decimal_Context_copy_impl (self , cls );
1688
+ }
1689
+
1676
1690
static PyObject *
1677
1691
context_copy (PyObject * self , PyObject * Py_UNUSED (dummy ))
1678
1692
{
1679
- return _decimal_Context_copy_impl (self );
1693
+ PyObject * copy ;
1694
+
1695
+ decimal_state * state = get_module_state_from_ctx (self );
1696
+ copy = PyObject_CallObject ((PyObject * )state -> PyDecContext_Type , NULL );
1697
+ if (copy == NULL ) {
1698
+ return NULL ;
1699
+ }
1700
+
1701
+ * CTX (copy ) = * CTX (self );
1702
+ CTX (copy )-> newtrap = 0 ;
1703
+ CtxCaps (copy ) = CtxCaps (self );
1704
+
1705
+ return copy ;
1680
1706
}
1681
1707
1708
+
1709
+ /*[clinic input]
1710
+ _decimal.Context.__reduce__ = _decimal.Context.copy
1711
+
1712
+ [clinic start generated code]*/
1713
+
1682
1714
static PyObject *
1683
- context_reduce (PyObject * self , PyObject * Py_UNUSED (dummy ))
1715
+ _decimal_Context___reduce___impl (PyObject * self , PyTypeObject * cls )
1716
+ /*[clinic end generated code: output=4e77de55efdbb56a input=787683f13d047ce8]*/
1684
1717
{
1685
1718
PyObject * flags ;
1686
1719
PyObject * traps ;
1687
1720
PyObject * ret ;
1688
1721
mpd_context_t * ctx ;
1689
- decimal_state * state = get_module_state_from_ctx ( self );
1722
+ decimal_state * state = PyType_GetModuleState ( cls );
1690
1723
1691
1724
ctx = CTX (self );
1692
1725
@@ -2978,6 +3011,7 @@ PyDecType_FromSequenceExact(PyTypeObject *type, PyObject *v,
2978
3011
@classmethod
2979
3012
_decimal.Decimal.from_float
2980
3013
3014
+ cls: defining_class
2981
3015
f as pyfloat: object
2982
3016
/
2983
3017
@@ -2997,13 +3031,14 @@ Decimal.from_float(0.1) is not the same as Decimal('0.1').
2997
3031
[clinic start generated code]*/
2998
3032
2999
3033
static PyObject *
3000
- _decimal_Decimal_from_float_impl (PyTypeObject * type , PyObject * pyfloat )
3001
- /*[clinic end generated code: output=e62775271ac469e6 input=052036648342f8c8]*/
3034
+ _decimal_Decimal_from_float_impl (PyTypeObject * type , PyTypeObject * cls ,
3035
+ PyObject * pyfloat )
3036
+ /*[clinic end generated code: output=fcb7d55d2f9dc790 input=03bc8dbe963e52ca]*/
3002
3037
{
3003
3038
PyObject * context ;
3004
3039
PyObject * result ;
3005
3040
3006
- decimal_state * state = get_module_state_by_def ( type );
3041
+ decimal_state * state = PyType_GetModuleState ( cls );
3007
3042
CURRENT_CONTEXT (state , context );
3008
3043
result = PyDecType_FromFloatExact (state -> PyDec_Type , pyfloat , context );
3009
3044
if (type != state -> PyDec_Type && result != NULL ) {
@@ -3018,9 +3053,10 @@ _decimal_Decimal_from_float_impl(PyTypeObject *type, PyObject *pyfloat)
3018
3053
an exact conversion. If the result does not meet the restrictions
3019
3054
for an mpd_t, fail with InvalidOperation. */
3020
3055
static PyObject *
3021
- PyDecType_FromNumberExact (PyTypeObject * type , PyObject * v , PyObject * context )
3056
+ PyDecType_FromNumberExact (PyTypeObject * type , PyTypeObject * cls ,
3057
+ PyObject * v , PyObject * context )
3022
3058
{
3023
- decimal_state * state = get_module_state_by_def ( type );
3059
+ decimal_state * state = PyType_GetModuleState ( cls );
3024
3060
assert (v != NULL );
3025
3061
if (PyDec_Check (state , v )) {
3026
3062
return PyDecType_FromDecimalExact (type , v , context );
@@ -3046,6 +3082,7 @@ PyDecType_FromNumberExact(PyTypeObject *type, PyObject *v, PyObject *context)
3046
3082
@classmethod
3047
3083
_decimal.Decimal.from_number
3048
3084
3085
+ cls: defining_class
3049
3086
number: object
3050
3087
/
3051
3088
@@ -3060,15 +3097,16 @@ Class method that converts a real number to a decimal number, exactly.
3060
3097
[clinic start generated code]*/
3061
3098
3062
3099
static PyObject *
3063
- _decimal_Decimal_from_number_impl (PyTypeObject * type , PyObject * number )
3064
- /*[clinic end generated code: output=41885304e5beea0a input=c58b678e8916f66b]*/
3100
+ _decimal_Decimal_from_number_impl (PyTypeObject * type , PyTypeObject * cls ,
3101
+ PyObject * number )
3102
+ /*[clinic end generated code: output=4d3ec722b7acfd8b input=271cb4feb3148804]*/
3065
3103
{
3066
3104
PyObject * context ;
3067
3105
PyObject * result ;
3068
3106
3069
- decimal_state * state = get_module_state_by_def ( type );
3107
+ decimal_state * state = PyType_GetModuleState ( cls );
3070
3108
CURRENT_CONTEXT (state , context );
3071
- result = PyDecType_FromNumberExact (state -> PyDec_Type , number , context );
3109
+ result = PyDecType_FromNumberExact (state -> PyDec_Type , cls , number , context );
3072
3110
if (type != state -> PyDec_Type && result != NULL ) {
3073
3111
Py_SETREF (result ,
3074
3112
PyObject_CallFunctionObjArgs ((PyObject * )type , result , NULL ));
@@ -3083,6 +3121,7 @@ _decimal_Decimal_from_number_impl(PyTypeObject *type, PyObject *number)
3083
3121
_decimal.Context.create_decimal_from_float
3084
3122
3085
3123
self as context: self
3124
+ cls: defining_class
3086
3125
f: object
3087
3126
/
3088
3127
@@ -3093,10 +3132,12 @@ the context limits.
3093
3132
[clinic start generated code]*/
3094
3133
3095
3134
static PyObject *
3096
- _decimal_Context_create_decimal_from_float (PyObject * context , PyObject * f )
3097
- /*[clinic end generated code: output=c660c343f6f7158b input=05a8c54b7a5b457b]*/
3135
+ _decimal_Context_create_decimal_from_float_impl (PyObject * context ,
3136
+ PyTypeObject * cls ,
3137
+ PyObject * f )
3138
+ /*[clinic end generated code: output=a5548f5140fa0870 input=8c66eeb22b01ddd4]*/
3098
3139
{
3099
- decimal_state * state = get_module_state_from_ctx ( context );
3140
+ decimal_state * state = PyType_GetModuleState ( cls );
3100
3141
return PyDec_FromFloat (state , f , context );
3101
3142
}
3102
3143
@@ -3702,6 +3743,7 @@ pydec_format(PyObject *dec, PyObject *context, PyObject *fmt, decimal_state *sta
3702
3743
_decimal.Decimal.__format__
3703
3744
3704
3745
self as dec: self
3746
+ cls: defining_class
3705
3747
format_spec as fmtarg: unicode
3706
3748
override: object = NULL
3707
3749
/
@@ -3710,9 +3752,9 @@ Formats the Decimal according to format_spec.
3710
3752
[clinic start generated code]*/
3711
3753
3712
3754
static PyObject *
3713
- _decimal_Decimal___format___impl (PyObject * dec , PyObject * fmtarg ,
3714
- PyObject * override )
3715
- /*[clinic end generated code: output=4b3640b7f0c8b6a5 input=e53488e49a0fff00 ]*/
3755
+ _decimal_Decimal___format___impl (PyObject * dec , PyTypeObject * cls ,
3756
+ PyObject * fmtarg , PyObject * override )
3757
+ /*[clinic end generated code: output=6d95f91bbb28b3ed input=2dbfaa0cbe243e9e ]*/
3716
3758
{
3717
3759
PyObject * result = NULL ;
3718
3760
PyObject * dot = NULL ;
@@ -3725,7 +3767,7 @@ _decimal_Decimal___format___impl(PyObject *dec, PyObject *fmtarg,
3725
3767
uint32_t status = 0 ;
3726
3768
int replace_fillchar = 0 ;
3727
3769
Py_ssize_t size ;
3728
- decimal_state * state = get_module_state_by_def ( Py_TYPE ( dec ) );
3770
+ decimal_state * state = PyType_GetModuleState ( cls );
3729
3771
CURRENT_CONTEXT (state , context );
3730
3772
fmt = (char * )PyUnicode_AsUTF8AndSize (fmtarg , & size );
3731
3773
if (fmt == NULL ) {
@@ -3929,15 +3971,17 @@ dec_as_long(PyObject *dec, PyObject *context, int round)
3929
3971
/*[clinic input]
3930
3972
_decimal.Decimal.as_integer_ratio
3931
3973
3974
+ cls: defining_class
3975
+
3932
3976
Return a pair of integers whose ratio is exactly equal to the original.
3933
3977
3934
3978
The ratio is in lowest terms and with a positive denominator.
3935
3979
Raise OverflowError on infinities and a ValueError on NaNs.
3936
3980
[clinic start generated code]*/
3937
3981
3938
3982
static PyObject *
3939
- _decimal_Decimal_as_integer_ratio_impl (PyObject * self )
3940
- /*[clinic end generated code: output=c5d88e900080c264 input=7861cb643f01525a ]*/
3983
+ _decimal_Decimal_as_integer_ratio_impl (PyObject * self , PyTypeObject * cls )
3984
+ /*[clinic end generated code: output=eb49c512701f844b input=07e33d8852184761 ]*/
3941
3985
{
3942
3986
PyObject * numerator = NULL ;
3943
3987
PyObject * denominator = NULL ;
@@ -3960,7 +4004,7 @@ _decimal_Decimal_as_integer_ratio_impl(PyObject *self)
3960
4004
return NULL ;
3961
4005
}
3962
4006
3963
- decimal_state * state = get_module_state_by_def ( Py_TYPE ( self ) );
4007
+ decimal_state * state = PyType_GetModuleState ( cls );
3964
4008
CURRENT_CONTEXT (state , context );
3965
4009
3966
4010
tmp = dec_alloc (state );
@@ -4130,7 +4174,7 @@ _decimal_Decimal_to_integral_exact_impl(PyObject *self, PyTypeObject *cls,
4130
4174
uint32_t status = 0 ;
4131
4175
mpd_context_t workctx ;
4132
4176
4133
- decimal_state * state = get_module_state_by_def ( Py_TYPE ( self ) );
4177
+ decimal_state * state = PyType_GetModuleState ( cls );
4134
4178
CONTEXT_CHECK_VA (state , context );
4135
4179
4136
4180
workctx = * CTX (context );
@@ -4193,20 +4237,22 @@ PyDec_AsFloat(PyObject *dec)
4193
4237
/*[clinic input]
4194
4238
_decimal.Decimal.__round__
4195
4239
4240
+ cls: defining_class
4196
4241
ndigits: object = NULL
4197
4242
/
4198
4243
4199
4244
Return the Integral closest to self, rounding half toward even.
4200
4245
[clinic start generated code]*/
4201
4246
4202
4247
static PyObject *
4203
- _decimal_Decimal___round___impl (PyObject * self , PyObject * ndigits )
4204
- /*[clinic end generated code: output=ca6b3570a8df0c91 input=dc72084114f59380]*/
4248
+ _decimal_Decimal___round___impl (PyObject * self , PyTypeObject * cls ,
4249
+ PyObject * ndigits )
4250
+ /*[clinic end generated code: output=790c2c6bd57890e6 input=d69e7178a58a66b1]*/
4205
4251
{
4206
4252
PyObject * result ;
4207
4253
uint32_t status = 0 ;
4208
4254
PyObject * context ;
4209
- decimal_state * state = get_module_state_by_def ( Py_TYPE ( self ) );
4255
+ decimal_state * state = PyType_GetModuleState ( cls );
4210
4256
CURRENT_CONTEXT (state , context );
4211
4257
if (ndigits ) {
4212
4258
mpd_uint_t dq [1 ] = {1 };
@@ -5101,37 +5147,41 @@ _dec_mpd_radix(decimal_state *state)
5101
5147
/*[clinic input]
5102
5148
_decimal.Decimal.radix
5103
5149
5150
+ cls: defining_class
5151
+
5104
5152
Return Decimal(10).
5105
5153
5106
5154
This is the radix (base) in which the Decimal class does
5107
5155
all its arithmetic. Included for compatibility with the specification.
5108
5156
[clinic start generated code]*/
5109
5157
5110
5158
static PyObject *
5111
- _decimal_Decimal_radix_impl (PyObject * self )
5112
- /*[clinic end generated code: output=6b1db4c3fcdb5ee1 input=18b72393549ca8fd ]*/
5159
+ _decimal_Decimal_radix_impl (PyObject * self , PyTypeObject * cls )
5160
+ /*[clinic end generated code: output=40a3bc7ec3d99228 input=b0d4cb9f870bbac1 ]*/
5113
5161
{
5114
- decimal_state * state = get_module_state_by_def ( Py_TYPE ( self ) );
5162
+ decimal_state * state = PyType_GetModuleState ( cls );
5115
5163
return _dec_mpd_radix (state );
5116
5164
}
5117
5165
5118
5166
/*[clinic input]
5119
5167
_decimal.Decimal.copy_abs
5120
5168
5169
+ cls: defining_class
5170
+
5121
5171
Return the absolute value of the argument.
5122
5172
5123
5173
This operation is unaffected by context and is quiet: no flags are
5124
5174
changed and no rounding is performed.
5125
5175
[clinic start generated code]*/
5126
5176
5127
5177
static PyObject *
5128
- _decimal_Decimal_copy_abs_impl (PyObject * self )
5129
- /*[clinic end generated code: output=fff53742cca94d70 input=a263c2e71d421f1b ]*/
5178
+ _decimal_Decimal_copy_abs_impl (PyObject * self , PyTypeObject * cls )
5179
+ /*[clinic end generated code: output=081cb7fb4230676e input=676d7c62b1795512 ]*/
5130
5180
{
5131
5181
PyObject * result ;
5132
5182
uint32_t status = 0 ;
5183
+ decimal_state * state = PyType_GetModuleState (cls );
5133
5184
5134
- decimal_state * state = get_module_state_by_def (Py_TYPE (self ));
5135
5185
if ((result = dec_alloc (state )) == NULL ) {
5136
5186
return NULL ;
5137
5187
}
@@ -5147,7 +5197,7 @@ _decimal_Decimal_copy_abs_impl(PyObject *self)
5147
5197
}
5148
5198
5149
5199
/*[clinic input]
5150
- _decimal.Decimal.copy_negate
5200
+ _decimal.Decimal.copy_negate = _decimal.Decimal.copy_abs
5151
5201
5152
5202
Return the negation of the argument.
5153
5203
@@ -5156,13 +5206,13 @@ changed and no rounding is performed.
5156
5206
[clinic start generated code]*/
5157
5207
5158
5208
static PyObject *
5159
- _decimal_Decimal_copy_negate_impl (PyObject * self )
5160
- /*[clinic end generated code: output=8551bc26dbc5d01d input=13d47ed3a5d228b1 ]*/
5209
+ _decimal_Decimal_copy_negate_impl (PyObject * self , PyTypeObject * cls )
5210
+ /*[clinic end generated code: output=04fed82c17d4e28b input=23f41ee8899f3891 ]*/
5161
5211
{
5162
5212
PyObject * result ;
5163
5213
uint32_t status = 0 ;
5214
+ decimal_state * state = PyType_GetModuleState (cls );
5164
5215
5165
- decimal_state * state = get_module_state_by_def (Py_TYPE (self ));
5166
5216
if ((result = dec_alloc (state )) == NULL ) {
5167
5217
return NULL ;
5168
5218
}
@@ -7336,8 +7386,8 @@ static PyMethodDef context_methods [] =
7336
7386
#endif
7337
7387
7338
7388
/* Miscellaneous */
7339
- { "__copy__" , context_copy , METH_NOARGS , NULL },
7340
- { "__reduce__" , context_reduce , METH_NOARGS , NULL },
7389
+ _DECIMAL_CONTEXT___COPY___METHODDEF
7390
+ _DECIMAL_CONTEXT___REDUCE___METHODDEF
7341
7391
_DECIMAL_CONTEXT_COPY_METHODDEF
7342
7392
_DECIMAL_CONTEXT_CREATE_DECIMAL_METHODDEF
7343
7393
_DECIMAL_CONTEXT_CREATE_DECIMAL_FROM_FLOAT_METHODDEF
0 commit comments