|
50 | 50 | #include <ctype.h> // isascii()
|
51 | 51 | #include <stdlib.h>
|
52 | 52 |
|
53 |
| -#include "docstrings.h" |
54 |
| - |
55 | 53 | #ifdef EXTRA_FUNCTIONALITY
|
56 | 54 | #define _PY_DEC_ROUND_GUARD MPD_ROUND_GUARD
|
57 | 55 | #else
|
@@ -1510,32 +1508,37 @@ context_dealloc(PyObject *self)
|
1510 | 1508 | Py_DECREF(tp);
|
1511 | 1509 | }
|
1512 | 1510 |
|
1513 |
| -static int |
1514 |
| -context_init(PyObject *self, PyObject *args, PyObject *kwds) |
1515 |
| -{ |
1516 |
| - static char *kwlist[] = { |
1517 |
| - "prec", "rounding", "Emin", "Emax", "capitals", "clamp", |
1518 |
| - "flags", "traps", NULL |
1519 |
| - }; |
1520 |
| - PyObject *prec = Py_None; |
1521 |
| - PyObject *rounding = Py_None; |
1522 |
| - PyObject *emin = Py_None; |
1523 |
| - PyObject *emax = Py_None; |
1524 |
| - PyObject *capitals = Py_None; |
1525 |
| - PyObject *clamp = Py_None; |
1526 |
| - PyObject *status = Py_None; |
1527 |
| - PyObject *traps = Py_None; |
1528 |
| - |
1529 |
| - assert(PyTuple_Check(args)); |
1530 |
| - |
1531 |
| - if (!PyArg_ParseTupleAndKeywords( |
1532 |
| - args, kwds, |
1533 |
| - "|OOOOOOOO", kwlist, |
1534 |
| - &prec, &rounding, &emin, &emax, &capitals, &clamp, &status, &traps |
1535 |
| - )) { |
1536 |
| - return -1; |
1537 |
| - } |
| 1511 | +/*[clinic input] |
| 1512 | +_decimal.Context.__init__ as context_init |
| 1513 | +
|
| 1514 | + prec: object = None |
| 1515 | + rounding: object = None |
| 1516 | + Emin as emin: object = None |
| 1517 | + Emax as emax: object = None |
| 1518 | + capitals: object = None |
| 1519 | + clamp: object = None |
| 1520 | + flags as status: object = None |
| 1521 | + traps: object = None |
| 1522 | +
|
| 1523 | +Create context. |
| 1524 | +
|
| 1525 | +The context affects almost all operations and controls rounding, |
| 1526 | +Over/Underflow, raising of exceptions and much more. A new context |
| 1527 | +can be constructed as follows: |
| 1528 | +
|
| 1529 | + >>> c = Context(prec=28, Emin=-425000000, Emax=425000000, |
| 1530 | + ... rounding=ROUND_HALF_EVEN, capitals=1, clamp=1, |
| 1531 | + ... traps=[InvalidOperation, DivisionByZero, Overflow], |
| 1532 | + ... flags=[]) |
| 1533 | + >>> |
| 1534 | +[clinic start generated code]*/ |
1538 | 1535 |
|
| 1536 | +static int |
| 1537 | +context_init_impl(PyObject *self, PyObject *prec, PyObject *rounding, |
| 1538 | + PyObject *emin, PyObject *emax, PyObject *capitals, |
| 1539 | + PyObject *clamp, PyObject *status, PyObject *traps) |
| 1540 | +/*[clinic end generated code: output=8bfdc59fbe862f44 input=45c704b93cd02959]*/ |
| 1541 | +{ |
1539 | 1542 | return context_setattrs(
|
1540 | 1543 | self, prec, rounding,
|
1541 | 1544 | emin, emax, capitals,
|
@@ -3210,17 +3213,25 @@ PyDec_FromObject(PyObject *v, PyObject *context)
|
3210 | 3213 | }
|
3211 | 3214 | }
|
3212 | 3215 |
|
| 3216 | +/*[clinic input] |
| 3217 | +@classmethod |
| 3218 | +_decimal.Decimal.__new__ as dec_new |
| 3219 | +
|
| 3220 | + value as v: object(c_default="NULL") = "0" |
| 3221 | + context: object = None |
| 3222 | +
|
| 3223 | +Construct a new Decimal object. |
| 3224 | +
|
| 3225 | +value can be an integer, string, tuple, or another Decimal object. If |
| 3226 | +no value is given, return Decimal('0'). The context does not affect |
| 3227 | +the conversion and is only passed to determine if the InvalidOperation |
| 3228 | +trap is active. |
| 3229 | +[clinic start generated code]*/ |
| 3230 | + |
3213 | 3231 | static PyObject *
|
3214 |
| -dec_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 3232 | +dec_new_impl(PyTypeObject *type, PyObject *v, PyObject *context) |
| 3233 | +/*[clinic end generated code: output=5371cbce41508fe7 input=6353a3563bea247b]*/ |
3215 | 3234 | {
|
3216 |
| - static char *kwlist[] = {"value", "context", NULL}; |
3217 |
| - PyObject *v = NULL; |
3218 |
| - PyObject *context = Py_None; |
3219 |
| - |
3220 |
| - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, |
3221 |
| - &v, &context)) { |
3222 |
| - return NULL; |
3223 |
| - } |
3224 | 3235 | decimal_state *state = get_module_state_by_def(type);
|
3225 | 3236 | CONTEXT_CHECK_VA(state, context);
|
3226 | 3237 |
|
@@ -6219,7 +6230,7 @@ static PyType_Slot dec_slots[] = {
|
6219 | 6230 | {Py_tp_repr, dec_repr},
|
6220 | 6231 | {Py_tp_hash, dec_hash},
|
6221 | 6232 | {Py_tp_str, dec_str},
|
6222 |
| - {Py_tp_doc, (void *)doc_decimal}, |
| 6233 | + {Py_tp_doc, (void *)dec_new__doc__}, |
6223 | 6234 | {Py_tp_richcompare, dec_richcompare},
|
6224 | 6235 | {Py_tp_methods, dec_methods},
|
6225 | 6236 | {Py_tp_getset, dec_getsets},
|
@@ -7864,7 +7875,7 @@ static PyType_Slot context_slots[] = {
|
7864 | 7875 | {Py_tp_repr, context_repr},
|
7865 | 7876 | {Py_tp_getattro, context_getattr},
|
7866 | 7877 | {Py_tp_setattro, context_setattr},
|
7867 |
| - {Py_tp_doc, (void *)doc_context}, |
| 7878 | + {Py_tp_doc, (void *)context_init__doc__}, |
7868 | 7879 | {Py_tp_methods, context_methods},
|
7869 | 7880 | {Py_tp_getset, context_getsets},
|
7870 | 7881 | {Py_tp_init, context_init},
|
@@ -8321,7 +8332,7 @@ static struct PyModuleDef_Slot _decimal_slots[] = {
|
8321 | 8332 | static struct PyModuleDef _decimal_module = {
|
8322 | 8333 | PyModuleDef_HEAD_INIT,
|
8323 | 8334 | .m_name = "decimal",
|
8324 |
| - .m_doc = doc__decimal, |
| 8335 | + .m_doc = "C decimal arithmetic module", |
8325 | 8336 | .m_size = sizeof(decimal_state),
|
8326 | 8337 | .m_methods = _decimal_methods,
|
8327 | 8338 | .m_slots = _decimal_slots,
|
|
0 commit comments