From 6f9bd809628715bc787eb0988f6652305379b4a8 Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Thu, 16 Apr 2026 06:53:42 +0000 Subject: [PATCH 1/2] backup 3.13 --- Lib/test/test_type_cache.py | 20 ++++++++++++++++++++ Objects/typeobject.c | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/Lib/test/test_type_cache.py b/Lib/test/test_type_cache.py index 8e2bb0c238257b..a6a6e8cbdc1053 100644 --- a/Lib/test/test_type_cache.py +++ b/Lib/test/test_type_cache.py @@ -1,4 +1,5 @@ """ Tests for the internal type cache in CPython. """ +import collections.abc import unittest import dis from test import support @@ -108,6 +109,25 @@ class HolderSub(Holder): Holder.set_value() HolderSub.value + def test_abc_register_invalidates_subclass_versions(self): + class Parent: + pass + + class Child(Parent): + pass + + type_assign_version(Parent) + type_assign_version(Child) + parent_version = type_get_version(Parent) + child_version = type_get_version(Child) + if parent_version == 0 or child_version == 0: + self.skipTest("Could not assign valid type versions") + + collections.abc.Mapping.register(Parent) + + self.assertEqual(type_get_version(Parent), 0) + self.assertEqual(type_get_version(Child), 0) + @support.cpython_only @requires_specialization class TypeCacheWithSpecializationTests(unittest.TestCase): diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 51d1ce573d12e1..7ae4cce02cf683 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -5398,6 +5398,15 @@ void _PyType_SetFlagsRecursive(PyTypeObject *self, unsigned long mask, unsigned long flags) { BEGIN_TYPE_LOCK(); + /* Ideally, changing flags and invalidating the old version tag would + happen in one step. For this backport, keep it simple and invalidate + first while holding TYPE_LOCK. Immutable types are skipped because + set_flags_recursive() does not modify them. */ + if (!PyType_HasFeature(self, Py_TPFLAGS_IMMUTABLETYPE) && + (self->tp_flags & mask) != flags) + { + type_modified_unlocked(self); + } set_flags_recursive(self, mask, flags); END_TYPE_LOCK(); } From 264f265d611b38c0a116da77d72f94cf89050ff4 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 23 May 2026 09:55:52 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2026-05-23-09-55-50.gh-issue-148450.2MEVqH.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-05-23-09-55-50.gh-issue-148450.2MEVqH.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-05-23-09-55-50.gh-issue-148450.2MEVqH.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-05-23-09-55-50.gh-issue-148450.2MEVqH.rst new file mode 100644 index 00000000000000..2a7d0d9bb3a7f7 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-05-23-09-55-50.gh-issue-148450.2MEVqH.rst @@ -0,0 +1 @@ +Fix ``abc.register()`` so it invalidates type version tags for registered classes.