https://github.com/python/cpython/commit/0768eed8b5890bf8242a4ef04f0c45f875e17c68
commit: 0768eed8b5890bf8242a4ef04f0c45f875e17c68
branch: main
author: An Long <[email protected]>
committer: eendebakpt <[email protected]>
date: 2026-10-12T20:50:59Z
summary:

gh-81057: Inline single-use error messages in _decimal and make the rest const 
(#156809)

Co-authored-by: Pieter Eendebak <[email protected]>

files:
M Modules/_decimal/_decimal.c
M Tools/c-analyzer/cpython/ignored.tsv

diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
index 1f7da94b2971e11..5eaba2fdbdf2d6a 100644
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -348,30 +348,6 @@ static const char *dec_signal_string[MPD_NUM_FLAGS] = {
     "Underflow",
 };
 
-static const char *invalid_rounding_err =
-"valid values for rounding are:\n\
-  [ROUND_CEILING, ROUND_FLOOR, ROUND_UP, ROUND_DOWN,\n\
-   ROUND_HALF_UP, ROUND_HALF_DOWN, ROUND_HALF_EVEN,\n\
-   ROUND_05UP]";
-
-static const char *invalid_signals_err =
-"valid values for signals are:\n\
-  [InvalidOperation, FloatOperation, DivisionByZero,\n\
-   Overflow, Underflow, Subnormal, Inexact, Rounded,\n\
-   Clamped]";
-
-#ifdef EXTRA_FUNCTIONALITY
-static const char *invalid_flags_err =
-"valid values for _flags or _traps are:\n\
-  signals:\n\
-    [DecIEEEInvalidOperation, DecFloatOperation, DecDivisionByZero,\n\
-     DecOverflow, DecUnderflow, DecSubnormal, DecInexact, DecRounded,\n\
-     DecClamped]\n\
-  conditions which trigger DecIEEEInvalidOperation:\n\
-    [DecInvalidOperation, DecConversionSyntax, DecDivisionImpossible,\n\
-     DecDivisionUndefined, DecFpuError, DecInvalidContext, DecMallocError]";
-#endif
-
 static int
 value_error_int(const char *mesg)
 {
@@ -442,7 +418,11 @@ exception_as_flag(decimal_state *state, PyObject *ex)
         }
     }
 
-    PyErr_SetString(PyExc_KeyError, invalid_signals_err);
+    PyErr_SetString(PyExc_KeyError,
+        "valid values for signals are:\n"
+        "  [InvalidOperation, FloatOperation, DivisionByZero,\n"
+        "   Overflow, Underflow, Subnormal, Inexact, Rounded,\n"
+        "   Clamped]");
     return DEC_INVALID_SIGNALS;
 }
 
@@ -601,7 +581,15 @@ long_as_flags(PyObject *v)
         return DEC_ERR_OCCURRED;
     }
     if (x < 0 || x > (long)MPD_Max_status) {
-        PyErr_SetString(PyExc_TypeError, invalid_flags_err);
+        PyErr_SetString(PyExc_TypeError,
+            "valid values for _flags or _traps are:\n"
+            "  signals:\n"
+            "    [DecIEEEInvalidOperation, DecFloatOperation, 
DecDivisionByZero,\n"
+            "     DecOverflow, DecUnderflow, DecSubnormal, DecInexact, 
DecRounded,\n"
+            "     DecClamped]\n"
+            "  conditions which trigger DecIEEEInvalidOperation:\n"
+            "    [DecInvalidOperation, DecConversionSyntax, 
DecDivisionImpossible,\n"
+            "     DecDivisionUndefined, DecFpuError, DecInvalidContext, 
DecMallocError]");
         return DEC_INVALID_SIGNALS;
     }
 
@@ -657,7 +645,11 @@ getround(decimal_state *state, PyObject *v)
         }
     }
 
-    return type_error_int(invalid_rounding_err);
+    return type_error_int(
+        "valid values for rounding are:\n"
+        "  [ROUND_CEILING, ROUND_FLOOR, ROUND_UP, ROUND_DOWN,\n"
+        "   ROUND_HALF_UP, ROUND_HALF_DOWN, ROUND_HALF_EVEN,\n"
+        "   ROUND_05UP]");
 }
 
 
@@ -671,7 +663,7 @@ getround(decimal_state *state, PyObject *v)
    initialized to new SignalDicts. Once a SignalDict is tied to
    a context, it cannot be deleted. */
 
-static const char *INVALID_SIGNALDICT_ERROR_MSG = "invalid signal dict";
+static const char *const INVALID_SIGNALDICT_ERROR_MSG = "invalid signal dict";
 
 static int
 signaldict_init(PyObject *self,
diff --git a/Tools/c-analyzer/cpython/ignored.tsv 
b/Tools/c-analyzer/cpython/ignored.tsv
index cc9b389ec1a9ad4..5529a52b0c45c26 100644
--- a/Tools/c-analyzer/cpython/ignored.tsv
+++ b/Tools/c-analyzer/cpython/ignored.tsv
@@ -240,11 +240,8 @@ Modules/_decimal/_decimal.c        -       
cond_map_template       -
 Modules/_decimal/_decimal.c    -       dec_signal_string       -
 Modules/_decimal/_decimal.c    -       dflt_ctx        -
 Modules/_decimal/_decimal.c    -       int_constants   -
-Modules/_decimal/_decimal.c    -       invalid_rounding_err    -
-Modules/_decimal/_decimal.c    -       invalid_signals_err     -
 Modules/_decimal/_decimal.c    -       signal_map_template     -
 Modules/_decimal/_decimal.c    -       ssize_constants -
-Modules/_decimal/_decimal.c    -       INVALID_SIGNALDICT_ERROR_MSG    -
 Modules/_elementtree.c -       ExpatMemoryHandler      -
 Modules/_hashopenssl.c -       py_hashes       -
 Modules/_hacl/Hacl_Hash_SHA1.c -       _h0     -

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to