From 072cd7c33627a90e9399d9d880d764407584b08e Mon Sep 17 00:00:00 2001 From: Pablo Galindo Salgado Date: Thu, 12 Feb 2026 11:45:28 +0000 Subject: [PATCH 1/5] gh-142349: Fix refcount corruption in lazy import specialization (#144733) Remove spurious Py_DECREF on borrowed ref in LOAD_GLOBAL specialization _PyDict_LookupIndexAndValue() returns a borrowed reference via _Py_dict_lookup(), but specialize_load_global_lock_held() called Py_DECREF(value) on it when bailing out for lazy imports. Each time the adaptive counter fired while a lazy import was still in globals, this stole one reference from the dict's object. With 8+ threads racing through LOAD_GLOBAL during concurrent lazy import resolution, enough triggers accumulated to drive the refcount to zero while the dict and other threads still referenced the object, causing use-after-free. --- Python/specialize.c | 1 - 1 file changed, 1 deletion(-) diff --git a/Python/specialize.c b/Python/specialize.c index 7c02e929d47d9e..5ba016f83ea077 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -1321,7 +1321,6 @@ specialize_load_global_lock_held( } if (value != NULL && PyLazyImport_CheckExact(value)) { SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_ATTR_MODULE_LAZY_VALUE); - Py_DECREF(value); goto fail; } PyInterpreterState *interp = _PyInterpreterState_GET(); From b6b72e766338490305f756e25b0e4725e1b31cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20S=C5=82awecki?= Date: Thu, 12 Feb 2026 15:12:49 +0100 Subject: [PATCH 2/5] gh-144285: Improve `AttributeError` attribute suggestions (#144299) --- Lib/idlelib/idle_test/test_run.py | 2 +- Lib/test/test_traceback.py | 58 ++++++++++--------- Lib/traceback.py | 23 +++++--- ...-02-07-16-31-42.gh-issue-144285.iyH9iL.rst | 3 + 4 files changed, 49 insertions(+), 37 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2026-02-07-16-31-42.gh-issue-144285.iyH9iL.rst diff --git a/Lib/idlelib/idle_test/test_run.py b/Lib/idlelib/idle_test/test_run.py index 83ecbffa2a197e..9a9d3b7b4e219c 100644 --- a/Lib/idlelib/idle_test/test_run.py +++ b/Lib/idlelib/idle_test/test_run.py @@ -44,7 +44,7 @@ def __eq__(self, other): "Or did you forget to import 'abc'?\n"), ('int.reel', AttributeError, "type object 'int' has no attribute 'reel'. " - "Did you mean: 'real'?\n"), + "Did you mean '.real' instead of '.reel'?\n"), ) @force_not_colorized diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index eaca62b12d3eb1..99ac7fd83d91cb 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -4176,25 +4176,25 @@ class CaseChangeOverSubstitution: BLuch = None for cls, suggestion in [ - (Addition, "'bluchin'?"), - (Substitution, "'blech'?"), - (Elimination, "'blch'?"), - (Addition, "'bluchin'?"), - (SubstitutionOverElimination, "'blach'?"), - (SubstitutionOverAddition, "'blach'?"), - (EliminationOverAddition, "'bluc'?"), - (CaseChangeOverSubstitution, "'BLuch'?"), + (Addition, "'.bluchin'"), + (Substitution, "'.blech'"), + (Elimination, "'.blch'"), + (Addition, "'.bluchin'"), + (SubstitutionOverElimination, "'.blach'"), + (SubstitutionOverAddition, "'.blach'"), + (EliminationOverAddition, "'.bluc'"), + (CaseChangeOverSubstitution, "'.BLuch'"), ]: actual = self.get_suggestion(cls(), 'bluch') - self.assertIn(suggestion, actual) + self.assertIn('Did you mean ' + suggestion, actual) def test_suggestions_underscored(self): class A: bluch = None - self.assertIn("'bluch'", self.get_suggestion(A(), 'blach')) - self.assertIn("'bluch'", self.get_suggestion(A(), '_luch')) - self.assertIn("'bluch'", self.get_suggestion(A(), '_bluch')) + self.assertIn("'.bluch'", self.get_suggestion(A(), 'blach')) + self.assertIn("'.bluch'", self.get_suggestion(A(), '_luch')) + self.assertIn("'.bluch'", self.get_suggestion(A(), '_bluch')) attr_function = self.attr_function class B: @@ -4202,13 +4202,13 @@ class B: def method(self, name): attr_function(self, name) - self.assertIn("'_bluch'", self.get_suggestion(B(), '_blach')) - self.assertIn("'_bluch'", self.get_suggestion(B(), '_luch')) - self.assertNotIn("'_bluch'", self.get_suggestion(B(), 'bluch')) + self.assertIn("'._bluch'", self.get_suggestion(B(), '_blach')) + self.assertIn("'._bluch'", self.get_suggestion(B(), '_luch')) + self.assertNotIn("'._bluch'", self.get_suggestion(B(), 'bluch')) - self.assertIn("'_bluch'", self.get_suggestion(partial(B().method, '_blach'))) - self.assertIn("'_bluch'", self.get_suggestion(partial(B().method, '_luch'))) - self.assertIn("'_bluch'", self.get_suggestion(partial(B().method, 'bluch'))) + self.assertIn("'._bluch'", self.get_suggestion(partial(B().method, '_blach'))) + self.assertIn("'._bluch'", self.get_suggestion(partial(B().method, '_luch'))) + self.assertIn("'._bluch'", self.get_suggestion(partial(B().method, 'bluch'))) def test_do_not_trigger_for_long_attributes(self): @@ -4256,7 +4256,7 @@ class A: fiⁿₐˡᵢᶻₐᵗᵢᵒₙ = None suggestion = self.get_suggestion(A(), 'fiⁿₐˡᵢᶻₐᵗᵢᵒₙ') - self.assertIn("'finalization'", suggestion) + self.assertIn("'.finalization'", suggestion) self.assertNotIn("analization", suggestion) class B: @@ -4264,8 +4264,10 @@ class B: attr_µ = None # attr_\xb5 suggestion = self.get_suggestion(B(), 'attr_\xb5') - self.assertIn("'attr_\u03bc'", suggestion) - self.assertIn(r"'attr_\u03bc'", suggestion) + self.assertIn( + "'.attr_\u03bc' ('attr_\\u03bc') " + "instead of '.attr_\xb5' ('attr_\\xb5')", + suggestion) self.assertNotIn("attr_a", suggestion) @@ -4371,11 +4373,11 @@ def __init__(self): # Should suggest 'inner.value' actual = self.get_suggestion(Outer(), 'value') - self.assertIn("Did you mean: 'inner.value'", actual) + self.assertIn("Did you mean '.inner.value' instead of '.value'", actual) # Should suggest 'inner.data' actual = self.get_suggestion(Outer(), 'data') - self.assertIn("Did you mean: 'inner.data'", actual) + self.assertIn("Did you mean '.inner.data' instead of '.data'", actual) def test_getattr_nested_prioritizes_direct_matches(self): # Test that direct attribute matches are prioritized over nested ones @@ -4390,7 +4392,7 @@ def __init__(self): # Should suggest 'fooo' (direct) not 'inner.foo' (nested) actual = self.get_suggestion(Outer(), 'foo') - self.assertIn("Did you mean: 'fooo'", actual) + self.assertIn("Did you mean '.fooo'", actual) self.assertNotIn("inner.foo", actual) def test_getattr_nested_with_property(self): @@ -4487,7 +4489,7 @@ def __init__(self): # Should suggest only the first match (alphabetically) actual = self.get_suggestion(Outer(), 'value') - self.assertIn("'a_inner.value'", actual) + self.assertIn("'.a_inner.value'", actual) # Verify it's a single suggestion, not multiple self.assertEqual(actual.count("Did you mean"), 1) @@ -4510,10 +4512,10 @@ def __init__(self): self.exploder = ExplodingProperty() # Accessing attributes will raise self.safe_inner = SafeInner() - # Should still suggest 'safe_inner.target' without crashing + # Should still suggest '.safe_inner.target' without crashing # even though accessing exploder.target would raise an exception actual = self.get_suggestion(Outer(), 'target') - self.assertIn("'safe_inner.target'", actual) + self.assertIn("'.safe_inner.target'", actual) def test_getattr_nested_handles_hasattr_exceptions(self): # Test that exceptions in hasattr don't crash the system @@ -4534,7 +4536,7 @@ def __init__(self): # Should still find 'normal.target' even though weird.target check fails actual = self.get_suggestion(Outer(), 'target') - self.assertIn("'normal.target'", actual) + self.assertIn("'.normal.target'", actual) def make_module(self, code): tmpdir = Path(tempfile.mkdtemp()) diff --git a/Lib/traceback.py b/Lib/traceback.py index b121733c27fd8c..42453b4867ce99 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -1128,7 +1128,16 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None, self._str += (". Site initialization is disabled, did you forget to " + "add the site-packages directory to sys.path " + "or to enable your virtual environment?") - elif exc_type and issubclass(exc_type, (NameError, AttributeError)) and \ + elif exc_type and issubclass(exc_type, AttributeError) and \ + getattr(exc_value, "name", None) is not None: + wrong_name = getattr(exc_value, "name", None) + suggestion = _compute_suggestion_error(exc_value, exc_traceback, wrong_name) + if suggestion: + if suggestion.isascii(): + self._str += f". Did you mean '.{suggestion}' instead of '.{wrong_name}'?" + else: + self._str += f". Did you mean '.{suggestion}' ({suggestion!a}) instead of '.{wrong_name}' ({wrong_name!a})?" + elif exc_type and issubclass(exc_type, NameError) and \ getattr(exc_value, "name", None) is not None: wrong_name = getattr(exc_value, "name", None) suggestion = _compute_suggestion_error(exc_value, exc_traceback, wrong_name) @@ -1137,13 +1146,11 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None, self._str += f". Did you mean: '{suggestion}'?" else: self._str += f". Did you mean: '{suggestion}' ({suggestion!a})?" - if issubclass(exc_type, NameError): - wrong_name = getattr(exc_value, "name", None) - if wrong_name is not None and wrong_name in sys.stdlib_module_names: - if suggestion: - self._str += f" Or did you forget to import '{wrong_name}'?" - else: - self._str += f". Did you forget to import '{wrong_name}'?" + if wrong_name is not None and wrong_name in sys.stdlib_module_names: + if suggestion: + self._str += f" Or did you forget to import '{wrong_name}'?" + else: + self._str += f". Did you forget to import '{wrong_name}'?" if lookup_lines: self._load_lines() self.__suppress_context__ = \ diff --git a/Misc/NEWS.d/next/Library/2026-02-07-16-31-42.gh-issue-144285.iyH9iL.rst b/Misc/NEWS.d/next/Library/2026-02-07-16-31-42.gh-issue-144285.iyH9iL.rst new file mode 100644 index 00000000000000..e1119a85e9c1f3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-02-07-16-31-42.gh-issue-144285.iyH9iL.rst @@ -0,0 +1,3 @@ +Attribute suggestions in :exc:`AttributeError` tracebacks are now formatted differently +to make them easier to understand, for example: ``Did you mean '.datetime.now' instead of '.now'``. +Contributed by Bartosz Sławecki. From eb6ebdbc95aa8d62ac3169e72aac164a21c5679c Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 12 Feb 2026 16:19:50 +0100 Subject: [PATCH 3/5] gh-138744: Upgrade Windows to 2025 in GitHub Actions (#144682) Replace windows-2022 with windows-2025. --- .github/workflows/jit.yml | 4 ++-- .github/workflows/reusable-windows-msi.yml | 2 +- .github/workflows/reusable-windows.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index cd6e9875d282d2..5a564b63f9d120 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -74,10 +74,10 @@ jobs: include: - target: i686-pc-windows-msvc/msvc architecture: Win32 - runner: windows-2022 + runner: windows-2025 - target: x86_64-pc-windows-msvc/msvc architecture: x64 - runner: windows-2022 + runner: windows-2025 - target: aarch64-pc-windows-msvc/msvc architecture: ARM64 runner: windows-11-arm diff --git a/.github/workflows/reusable-windows-msi.yml b/.github/workflows/reusable-windows-msi.yml index c7611804369600..96fc338c47bf29 100644 --- a/.github/workflows/reusable-windows-msi.yml +++ b/.github/workflows/reusable-windows-msi.yml @@ -17,7 +17,7 @@ env: jobs: build: name: installer for ${{ inputs.arch }} - runs-on: ${{ inputs.arch == 'arm64' && 'windows-11-arm' || 'windows-2022' }} + runs-on: ${{ inputs.arch == 'arm64' && 'windows-11-arm' || 'windows-2025' }} timeout-minutes: 60 env: ARCH: ${{ inputs.arch }} diff --git a/.github/workflows/reusable-windows.yml b/.github/workflows/reusable-windows.yml index 82ea819867ef6d..2f6caf2f0044d4 100644 --- a/.github/workflows/reusable-windows.yml +++ b/.github/workflows/reusable-windows.yml @@ -21,7 +21,7 @@ env: jobs: build: name: Build and test (${{ inputs.arch }}) - runs-on: ${{ inputs.arch == 'arm64' && 'windows-11-arm' || 'windows-2022' }} + runs-on: ${{ inputs.arch == 'arm64' && 'windows-11-arm' || 'windows-2025' }} timeout-minutes: 60 env: ARCH: ${{ inputs.arch }} From 9e5e1f9988faee0a18969d4d7dda6a3e4eaf850b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 12 Feb 2026 17:03:55 +0100 Subject: [PATCH 4/5] gh-121617: Include for Py_CLEAR() macro (#144666) Python.h now also includes in the limited C API version 3.11 and newer to fix the Py_CLEAR() macro which uses memcpy(). Add a Py_CLEAR() test in test_cext. Modify also _Py_TYPEOF to use C23 typeof() if available. --- Doc/c-api/intro.rst | 2 +- Include/Python.h | 4 ++-- Include/pyport.h | 7 +++++-- Lib/test/test_cext/extension.c | 6 +++++- .../C_API/2026-02-10-14-49-49.gh-issue-121617.57vMqa.rst | 3 +++ 5 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 Misc/NEWS.d/next/C_API/2026-02-10-14-49-49.gh-issue-121617.57vMqa.rst diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index a5dfbe7f4e1305..c3a80234f86116 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -123,6 +123,7 @@ System includes * ```` * ```` * ```` + * ```` * ```` * ```` (if present) @@ -138,7 +139,6 @@ System includes * ```` * ```` * ```` - * ```` .. note:: diff --git a/Include/Python.h b/Include/Python.h index 78083bbf31db75..17cbc083241514 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -22,12 +22,13 @@ #include // INT_MAX #include // HUGE_VAL #include // va_list +#include // memcpy() #include // wchar_t #ifdef HAVE_SYS_TYPES_H # include // ssize_t #endif -// , , and headers are no longer used +// , and headers are no longer used // by Python, but kept for the backward compatibility of existing third party C // extensions. They are not included by limited C API version 3.11 and newer. // @@ -37,7 +38,6 @@ # include // errno # include // FILE* # include // getenv() -# include // memcpy() #endif #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030d0000 # include // tolower() diff --git a/Include/pyport.h b/Include/pyport.h index 61e2317976eed1..1e1702abd99a2c 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -567,8 +567,11 @@ extern "C" { // // Example: _Py_TYPEOF(x) x_copy = (x); // -// The macro is only defined if GCC or clang compiler is used. -#if defined(__GNUC__) || defined(__clang__) +// On C23, use typeof(). Otherwise, the macro is only defined +// if GCC or clang compiler is used. +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +# define _Py_TYPEOF(expr) typeof(expr) +#elif defined(__GNUC__) || defined(__clang__) # define _Py_TYPEOF(expr) __typeof__(expr) #endif diff --git a/Lib/test/test_cext/extension.c b/Lib/test/test_cext/extension.c index a2f6151d8b36ed..a6b30fd627fe99 100644 --- a/Lib/test/test_cext/extension.c +++ b/Lib/test/test_cext/extension.c @@ -76,7 +76,7 @@ static PyMethodDef _testcext_methods[] = { static int _testcext_exec(PyObject *module) { - PyObject *result; + PyObject *result, *obj; #ifdef __STDC_VERSION__ if (PyModule_AddIntMacro(module, __STDC_VERSION__) < 0) { @@ -92,6 +92,10 @@ _testcext_exec(PyObject *module) Py_BUILD_ASSERT(sizeof(int) == sizeof(unsigned int)); assert(Py_BUILD_ASSERT_EXPR(sizeof(int) == sizeof(unsigned int)) == 0); + // Test Py_CLEAR() + obj = NULL; + Py_CLEAR(obj); + return 0; } diff --git a/Misc/NEWS.d/next/C_API/2026-02-10-14-49-49.gh-issue-121617.57vMqa.rst b/Misc/NEWS.d/next/C_API/2026-02-10-14-49-49.gh-issue-121617.57vMqa.rst new file mode 100644 index 00000000000000..cf84f8b1b0d36b --- /dev/null +++ b/Misc/NEWS.d/next/C_API/2026-02-10-14-49-49.gh-issue-121617.57vMqa.rst @@ -0,0 +1,3 @@ +``Python.h`` now also includes ```` in the limited C API version 3.11 +and newer to fix the :c:macro:`Py_CLEAR` macro which uses ``memcpy()``. Patch +by Victor Stinner. From e66f4a5a9c7ce744030d6352bf5575639b1096cc Mon Sep 17 00:00:00 2001 From: James Date: Thu, 12 Feb 2026 11:50:40 -0500 Subject: [PATCH 5/5] gh-80667: Fix case-sensitivity of some Unicode literal escapes (GH-107281) Lookup for CJK ideograms and Hangul syllables is now case-insensitive, as is the case for other character names. --- Lib/test/test_ucn.py | 8 ++++++++ .../2023-07-26-00-03-00.gh-issue-80667.N7Dh8B.rst | 2 ++ Modules/unicodedata.c | 15 ++++++++------- 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2023-07-26-00-03-00.gh-issue-80667.N7Dh8B.rst diff --git a/Lib/test/test_ucn.py b/Lib/test/test_ucn.py index 0e2c25aaff2fe9..0c641a455c0747 100644 --- a/Lib/test/test_ucn.py +++ b/Lib/test/test_ucn.py @@ -88,6 +88,9 @@ def test_hangul_syllables(self): self.checkletter("HANGUL SYLLABLE HWEOK", "\ud6f8") self.checkletter("HANGUL SYLLABLE HIH", "\ud7a3") + self.checkletter("haNGul SYllABle WAe", '\uc65c') + self.checkletter("HAngUL syLLabLE waE", '\uc65c') + self.assertRaises(ValueError, unicodedata.name, "\ud7a4") def test_cjk_unified_ideographs(self): @@ -103,6 +106,11 @@ def test_cjk_unified_ideographs(self): self.checkletter("CJK UNIFIED IDEOGRAPH-2B81D", "\U0002B81D") self.checkletter("CJK UNIFIED IDEOGRAPH-3134A", "\U0003134A") + self.checkletter("cjK UniFIeD idEogRAph-3aBc", "\u3abc") + self.checkletter("CJk uNIfiEd IDeOGraPH-3AbC", "\u3abc") + self.checkletter("cjK UniFIeD idEogRAph-2aBcD", "\U0002abcd") + self.checkletter("CJk uNIfiEd IDeOGraPH-2AbCd", "\U0002abcd") + def test_bmp_characters(self): for code in range(0x10000): char = chr(code) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2023-07-26-00-03-00.gh-issue-80667.N7Dh8B.rst b/Misc/NEWS.d/next/Core_and_Builtins/2023-07-26-00-03-00.gh-issue-80667.N7Dh8B.rst new file mode 100644 index 00000000000000..db87a5ed9c7fc2 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2023-07-26-00-03-00.gh-issue-80667.N7Dh8B.rst @@ -0,0 +1,2 @@ +Literals using the ``\N{name}`` escape syntax can now construct CJK +ideographs and Hangul syllables using case-insensitive names. diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c index 091e6bcb9f3f49..44ffedec3840fe 100644 --- a/Modules/unicodedata.c +++ b/Modules/unicodedata.c @@ -1405,7 +1405,7 @@ find_syllable(const char *str, int *len, int *pos, int count, int column) len1 = Py_SAFE_DOWNCAST(strlen(s), size_t, int); if (len1 <= *len) continue; - if (strncmp(str, s, len1) == 0) { + if (PyOS_strnicmp(str, s, len1) == 0) { *len = len1; *pos = i; } @@ -1437,7 +1437,7 @@ _getcode(const char* name, int namelen, Py_UCS4* code) * PUA */ /* Check for hangul syllables. */ - if (strncmp(name, "HANGUL SYLLABLE ", 16) == 0) { + if (PyOS_strnicmp(name, "HANGUL SYLLABLE ", 16) == 0) { int len, L = -1, V = -1, T = -1; const char *pos = name + 16; find_syllable(pos, &len, &L, LCount, 0); @@ -1455,7 +1455,7 @@ _getcode(const char* name, int namelen, Py_UCS4* code) } /* Check for unified ideographs. */ - if (strncmp(name, "CJK UNIFIED IDEOGRAPH-", 22) == 0) { + if (PyOS_strnicmp(name, "CJK UNIFIED IDEOGRAPH-", 22) == 0) { /* Four or five hexdigits must follow. */ unsigned int v; v = 0; @@ -1465,10 +1465,11 @@ _getcode(const char* name, int namelen, Py_UCS4* code) return 0; while (namelen--) { v *= 16; - if (*name >= '0' && *name <= '9') - v += *name - '0'; - else if (*name >= 'A' && *name <= 'F') - v += *name - 'A' + 10; + Py_UCS1 c = Py_TOUPPER(*name); + if (c >= '0' && c <= '9') + v += c - '0'; + else if (c >= 'A' && c <= 'F') + v += c - 'A' + 10; else return 0; name++;