From 95b79efffc0d3c04ff46f1e261f59d27c23608e9 Mon Sep 17 00:00:00 2001 From: Xiaowei Lu Date: Fri, 3 Jul 2026 18:34:15 +0800 Subject: [PATCH] gh-152870: Fix compile error with decimal when EXTRA_FUNCTIONALITY enabled (GH-152871) (cherry picked from commit c4739533f335f9cd4fa71ba6daff2a81751da643) Co-authored-by: Xiaowei Lu --- Lib/test/test_decimal.py | 8 ++++++++ .../Build/2026-07-02-16-25-13.gh-issue-152870.oh9eD1.rst | 4 ++++ Modules/_decimal/_decimal.c | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Build/2026-07-02-16-25-13.gh-issue-152870.oh9eD1.rst diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index fe8c8ce12da0bfa..a04ed0c83c07c4a 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -4967,6 +4967,14 @@ def test_c_context(self): self.assertEqual(c._flags, C.DecClamped) self.assertEqual(c._traps, C.DecRounded) + @requires_extra_functionality + def test_c_context_apply(self): + c = C.Context(prec=3) + self.assertEqual(c.apply(C.Decimal('1.23456')), C.Decimal('1.23')) + # A higher precision won't see them as equal. + c = C.Context(prec=5) + self.assertNotEqual(c.apply(C.Decimal('1.23456')), C.Decimal('1.23')) + @requires_extra_functionality def test_constants(self): # Condition flags diff --git a/Misc/NEWS.d/next/Build/2026-07-02-16-25-13.gh-issue-152870.oh9eD1.rst b/Misc/NEWS.d/next/Build/2026-07-02-16-25-13.gh-issue-152870.oh9eD1.rst new file mode 100644 index 000000000000000..eaddd22a60fc09b --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-07-02-16-25-13.gh-issue-152870.oh9eD1.rst @@ -0,0 +1,4 @@ +Fix a compilation error in the :mod:`decimal` C extension (``_decimal``) when +it is built with ``EXTRA_FUNCTIONALITY``. ``Context.apply()`` called the +internal ``_apply`` helper using its pre-Argument-Clinic signature; the call is +now made through the generated ``_impl`` function. diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index 2760792a3fe18ed..7a3240a3636a9cb 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -6993,7 +6993,7 @@ _decimal_Context_apply_impl(PyObject *context, PyTypeObject *cls, PyObject *x) /*[clinic end generated code: output=f8a7142d47ad4ff3 input=388e66ca82733516]*/ { - return _decimal_Context__apply(context, x); + return _decimal_Context__apply_impl(context, cls, x); } #endif