|
58 | 58 |
|
59 | 59 | #include "clinic/_decimal.c.h" |
60 | 60 |
|
| 61 | +#define MPD_SPEC_VERSION "1.70" // Highest version of the spec this complies with |
| 62 | + // See https://speleotrove.com/decimal/decarith.html |
| 63 | + |
61 | 64 | /*[clinic input] |
62 | 65 | module _decimal |
63 | 66 | class _decimal.Decimal "PyObject *" "&dec_spec" |
@@ -7566,12 +7569,35 @@ static PyType_Spec context_spec = { |
7566 | 7569 | }; |
7567 | 7570 |
|
7568 | 7571 |
|
| 7572 | +static PyObject * |
| 7573 | +decimal_getattr(PyObject *self, PyObject *args) |
| 7574 | +{ |
| 7575 | + PyObject *name; |
| 7576 | + if (!PyArg_UnpackTuple(args, "__getattr__", 1, 1, &name)) { |
| 7577 | + return NULL; |
| 7578 | + } |
| 7579 | + |
| 7580 | + if (PyUnicode_Check(name) && PyUnicode_EqualToUTF8(name, "__version__")) { |
| 7581 | + if (PyErr_WarnEx(PyExc_DeprecationWarning, |
| 7582 | + "'__version__' is deprecated and slated for removal in Python 3.20", |
| 7583 | + 1) < 0) { |
| 7584 | + return NULL; |
| 7585 | + } |
| 7586 | + return PyUnicode_FromString(MPD_SPEC_VERSION); |
| 7587 | + } |
| 7588 | + |
| 7589 | + PyErr_Format(PyExc_AttributeError, "module 'decimal' has no attribute %R", name); |
| 7590 | + return NULL; |
| 7591 | +} |
| 7592 | + |
| 7593 | + |
7569 | 7594 | static PyMethodDef _decimal_methods [] = |
7570 | 7595 | { |
7571 | 7596 | _DECIMAL_GETCONTEXT_METHODDEF |
7572 | 7597 | _DECIMAL_SETCONTEXT_METHODDEF |
7573 | 7598 | _DECIMAL_LOCALCONTEXT_METHODDEF |
7574 | 7599 | _DECIMAL_IEEECONTEXT_METHODDEF |
| 7600 | + {"__getattr__", decimal_getattr, METH_VARARGS, "Module __getattr__"}, |
7575 | 7601 | { NULL, NULL, 1, NULL } |
7576 | 7602 | }; |
7577 | 7603 |
|
@@ -7891,7 +7917,7 @@ _decimal_exec(PyObject *m) |
7891 | 7917 | } |
7892 | 7918 |
|
7893 | 7919 | /* Add specification version number */ |
7894 | | - CHECK_INT(PyModule_AddStringConstant(m, "__version__", "1.70")); |
| 7920 | + CHECK_INT(PyModule_AddStringConstant(m, "SPEC_VERSION", MPD_SPEC_VERSION)); |
7895 | 7921 | CHECK_INT(PyModule_AddStringConstant(m, "__libmpdec_version__", mpd_version())); |
7896 | 7922 |
|
7897 | 7923 | return 0; |
|
0 commit comments