- :mod:`argparse`
- :mod:`csv`
- :mod:`!ctypes.macholib`
+ - :mod:`decimal` (use :data:`decimal.SPEC_VERSION` instead)
- :mod:`imaplib`
- :mod:`ipaddress`
- :mod:`json`
Constants
---------
-The constants in this section are only relevant for the C module. They
+.. data:: SPEC_VERSION
+
+ The highest version of the General Decimal Arithmetic
+ Specification that this implementation complies with.
+ See https://speleotrove.com/decimal/decarith.html for the specification.
+
+ .. versionadded:: next
+
+
+The following constants are only relevant for the C module. They
are also included in the pure Python version for compatibility.
+---------------------------------+---------------------+-------------------------------+
- :mod:`argparse`
- :mod:`csv`
- :mod:`!ctypes.macholib`
+ - :mod:`decimal` (use :data:`decimal.SPEC_VERSION` instead)
- :mod:`imaplib`
- :mod:`ipaddress`
- :mod:`json`
'HAVE_THREADS',
# C version: compile time choice that enables the coroutine local context
- 'HAVE_CONTEXTVAR'
+ 'HAVE_CONTEXTVAR',
+
+ # Highest version of the spec this module complies with
+ 'SPEC_VERSION',
]
__xname__ = __name__ # sys.modules lookup (--without-threads)
__name__ = 'decimal' # For pickling
-__version__ = '1.70' # Highest version of the spec this complies with
- # See http://speleotrove.com/decimal/
+SPEC_VERSION = '1.70' # Highest version of the spec this complies with
+ # See https://speleotrove.com/decimal/decarith.html
__libmpdec_version__ = "2.4.2" # compatible libmpdec version
import math as _math
# _PyHASH_10INV is the inverse of 10 modulo the prime _PyHASH_MODULUS
_PyHASH_10INV = pow(10, _PyHASH_MODULUS - 2, _PyHASH_MODULUS)
del sys
+
+def __getattr__(name):
+ if name == "__version__":
+ from warnings import _deprecated
+
+ _deprecated("__version__", remove=(3, 20))
+ return SPEC_VERSION
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
try:
from _decimal import *
- from _decimal import __version__ # noqa: F401
from _decimal import __libmpdec_version__ # noqa: F401
+ from _decimal import __getattr__ # noqa: F401
except ImportError:
import _pydecimal
import sys
self.assertTrue(C.HAVE_THREADS is True or C.HAVE_THREADS is False)
self.assertTrue(P.HAVE_THREADS is True or P.HAVE_THREADS is False)
- self.assertEqual(C.__version__, P.__version__)
+ self.assertEqual(C.SPEC_VERSION, P.SPEC_VERSION)
self.assertLessEqual(set(dir(C)), set(dir(P)))
self.assertEqual([n for n in dir(C) if n[:2] != '__'], sorted(P.__all__))
doit('Context')
+class TestModule:
+ def test_deprecated__version__(self):
+ with self.assertWarnsRegex(
+ DeprecationWarning,
+ "'__version__' is deprecated and slated for removal in Python 3.20",
+ ) as cm:
+ getattr(self.decimal, "__version__")
+ self.assertEqual(cm.filename, __file__)
+
+
+@requires_cdecimal
+class CTestModule(TestModule, unittest.TestCase):
+ decimal = C
+class PyTestModule(TestModule, unittest.TestCase):
+ decimal = P
+
+
def load_tests(loader, tests, pattern):
if TODO_TESTS is not None:
# Run only Arithmetic tests
--- /dev/null
+:mod:`decimal`: Deprecate ``__version__`` and replace with
+:data:`decimal.SPEC_VERSION`.
#include "clinic/_decimal.c.h"
+#define MPD_SPEC_VERSION "1.70" // Highest version of the spec this complies with
+ // See https://speleotrove.com/decimal/decarith.html
+
/*[clinic input]
module _decimal
class _decimal.Decimal "PyObject *" "&dec_spec"
};
+static PyObject *
+decimal_getattr(PyObject *self, PyObject *args)
+{
+ PyObject *name;
+ if (!PyArg_UnpackTuple(args, "__getattr__", 1, 1, &name)) {
+ return NULL;
+ }
+
+ if (PyUnicode_Check(name) && PyUnicode_EqualToUTF8(name, "__version__")) {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "'__version__' is deprecated and slated for removal in Python 3.20",
+ 1) < 0) {
+ return NULL;
+ }
+ return PyUnicode_FromString(MPD_SPEC_VERSION);
+ }
+
+ PyErr_Format(PyExc_AttributeError, "module 'decimal' has no attribute %R", name);
+ return NULL;
+}
+
+
static PyMethodDef _decimal_methods [] =
{
_DECIMAL_GETCONTEXT_METHODDEF
_DECIMAL_SETCONTEXT_METHODDEF
_DECIMAL_LOCALCONTEXT_METHODDEF
_DECIMAL_IEEECONTEXT_METHODDEF
+ {"__getattr__", decimal_getattr, METH_VARARGS, "Module __getattr__"},
{ NULL, NULL, 1, NULL }
};
}
/* Add specification version number */
- CHECK_INT(PyModule_AddStringConstant(m, "__version__", "1.70"));
+ CHECK_INT(PyModule_AddStringConstant(m, "SPEC_VERSION", MPD_SPEC_VERSION));
CHECK_INT(PyModule_AddStringConstant(m, "__libmpdec_version__", mpd_version()));
return 0;