Skip to content

Commit 8c30b2c

Browse files
Commit
1 parent 1bfe86c commit 8c30b2c

File tree

8 files changed

+44
-5
lines changed

8 files changed

+44
-5
lines changed

Doc/deprecations/pending-removal-in-3.20.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Pending removal in Python 3.20
88
- :mod:`argparse`
99
- :mod:`csv`
1010
- :mod:`!ctypes.macholib`
11+
- :mod:`decimal` (Use :data:`decimal.SPEC_VERSION` instead)
1112
- :mod:`ipaddress`
1213
- :mod:`json`
1314
- :mod:`logging` (``__date__`` also deprecated)

Doc/library/decimal.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,14 @@ are also included in the pure Python version for compatibility.
16011601

16021602
.. versionadded:: 3.8.3
16031603

1604+
.. data:: SPEC_VERSION
1605+
1606+
The highest version of the General Decimal Arithmetic
1607+
Specification that this implementation complies with.
1608+
See https://speleotrove.com/decimal/ for the specification.
1609+
1610+
.. versionadded:: next
1611+
16041612

16051613
Rounding modes
16061614
--------------

Doc/whatsnew/3.15.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ New deprecations
825825
- :mod:`argparse`
826826
- :mod:`csv`
827827
- :mod:`!ctypes.macholib`
828+
- :mod:`decimal` (Use :data:`decimal.SPEC_VERSION` instead)
828829
- :mod:`ipaddress`
829830
- :mod:`json`
830831
- :mod:`logging` (``__date__`` also deprecated)

Lib/_pydecimal.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,16 @@
4747
'HAVE_THREADS',
4848

4949
# C version: compile time choice that enables the coroutine local context
50-
'HAVE_CONTEXTVAR'
50+
'HAVE_CONTEXTVAR',
51+
52+
# Highest version of the spec this module complies with
53+
'SPEC_VERSION'
5154
]
5255

5356
__xname__ = __name__ # sys.modules lookup (--without-threads)
5457
__name__ = 'decimal' # For pickling
55-
__version__ = '1.70' # Highest version of the spec this complies with
56-
# See http://speleotrove.com/decimal/
58+
SPEC_VERSION = '1.70' # Highest version of the spec this complies with
59+
# See https://speleotrove.com/decimal/
5760
__libmpdec_version__ = "2.4.2" # compatible libmpdec version
5861

5962
import math as _math

Lib/decimal.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,17 @@
100100

101101
try:
102102
from _decimal import *
103-
from _decimal import __version__ # noqa: F401
104103
from _decimal import __libmpdec_version__ # noqa: F401
105104
except ImportError:
106105
import _pydecimal
107106
import sys
108107
_pydecimal.__doc__ = __doc__
109108
sys.modules[__name__] = _pydecimal
109+
110+
def __getattr__(name):
111+
if name == "__version__":
112+
from warnings import _deprecated
113+
114+
_deprecated("__version__", remove=(3, 20))
115+
return "1.70" # Do not change
116+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

Lib/test/test_decimal.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5929,6 +5929,23 @@ def doit(ty):
59295929
doit('Context')
59305930

59315931

5932+
class TestModule:
5933+
def test_deprecated__version__(self):
5934+
with self.assertWarnsRegex(
5935+
DeprecationWarning,
5936+
"'__version__' is deprecated and slated for removal in Python 3.20",
5937+
) as cm:
5938+
getattr(self.decimal, "__version__")
5939+
self.assertEqual(cm.filename, __file__)
5940+
5941+
5942+
@requires_cdecimal
5943+
class CTestModule(TestModule, unittest.TestCase):
5944+
decimal = C
5945+
class PyTestModule(TestModule, unittest.TestCase):
5946+
decimal = P
5947+
5948+
59325949
def load_tests(loader, tests, pattern):
59335950
if TODO_TESTS is not None:
59345951
# Run only Arithmetic tests
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`decimal`: Deprecate ``__version__`` and replace with
2+
:data:`decimal.SPEC_VERSION`.

Modules/_decimal/_decimal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7891,7 +7891,7 @@ _decimal_exec(PyObject *m)
78917891
}
78927892

78937893
/* Add specification version number */
7894-
CHECK_INT(PyModule_AddStringConstant(m, "__version__", "1.70"));
7894+
CHECK_INT(PyModule_AddStringConstant(m, "SPEC_VERSION", "1.70"));
78957895
CHECK_INT(PyModule_AddStringConstant(m, "__libmpdec_version__", mpd_version()));
78967896

78977897
return 0;

0 commit comments

Comments
 (0)