From e7eab7da1d3850b55b18d80b9a9c8b60d63a6043 Mon Sep 17 00:00:00 2001 From: lipengyu Date: Sun, 25 Oct 2026 19:00:21 +0800 Subject: [PATCH] Fix inaccurate wording in multiple decimal module docstrings --- Lib/_pydecimal.py | 9 +++++---- Modules/_decimal/docstrings.h | 10 ++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Lib/_pydecimal.py b/Lib/_pydecimal.py index f4e849d889a3009..158409ef6ff6cf3 100644 --- a/Lib/_pydecimal.py +++ b/Lib/_pydecimal.py @@ -5155,8 +5155,8 @@ def number_class(self, a): """Returns an indication of the class of the operand. The class is one of the following strings: - -sNaN - -NaN + sNaN + NaN -Infinity -Normal -Subnormal @@ -5665,8 +5665,9 @@ def to_integral_value(self, a): When the operand has a negative exponent, the result is the same as using the quantize() operation using the given operand as the left-hand-operand, 1E+0 as the right-hand-operand, and the precision - of the operand as the precision setting, except that no flags will - be set. The rounding mode is taken from the context. + of the operand as the precision setting, except that the Inexact and + Rounded flags will not be set. The rounding mode is taken from the + context. >>> ExtendedContext.to_integral_value(Decimal('2.1')) Decimal('2') diff --git a/Modules/_decimal/docstrings.h b/Modules/_decimal/docstrings.h index 3a0d54e1f9a957b..9d13d641e866743 100644 --- a/Modules/_decimal/docstrings.h +++ b/Modules/_decimal/docstrings.h @@ -586,7 +586,13 @@ Return the sum of x and y.\n\ PyDoc_STRVAR(doc_ctx_canonical, "canonical($self, x, /)\n--\n\n\ -Return a new instance of x.\n\ +Returns the same Decimal object.\n\ +\n\ +As we do not have different encodings for the same number, the\n\ +received object already is in its canonical form.\n\ +\n\ +>>> ExtendedContext.canonical(Decimal('2.50'))\n\ +Decimal('2.50')\n\ \n"); PyDoc_STRVAR(doc_ctx_compare, @@ -867,7 +873,7 @@ the context to the result.\n\ PyDoc_STRVAR(doc_ctx_power, "power($self, /, a, b, modulo=None)\n--\n\n\ Compute a**b. If 'a' is negative, then 'b' must be integral. The result\n\ -will be inexact unless 'a' is integral and the result is finite and can\n\ +will be inexact unless 'b' is integral and the result is finite and can\n\ be expressed exactly in 'precision' digits. In the Python version the\n\ result is always correctly rounded, in the C version the result is almost\n\ always correctly rounded.\n\