https://github.com/python/cpython/commit/30c698a655bafdb53db0d39426a2b5cfce3b19ca
commit: 30c698a655bafdb53db0d39426a2b5cfce3b19ca
branch: main
author: Neko Asakura <[email protected]>
committer: Fidget-Spinner <[email protected]>
date: 2026-04-12T20:54:03+08:00
summary:

gh-148398: add type watcher in `_CHECK_ATTR_CLASS` (GH-148399)

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-04-11-15-12-53.gh-issue-148398.g62jCA.rst
M Python/optimizer_bytecodes.c
M Python/optimizer_cases.c.h

diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2026-04-11-15-12-53.gh-issue-148398.g62jCA.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-11-15-12-53.gh-issue-148398.g62jCA.rst
new file mode 100644
index 00000000000000..0a7ba0b27d9708
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-11-15-12-53.gh-issue-148398.g62jCA.rst
@@ -0,0 +1 @@
+Fix a bug in the JIT optimizer where class attribute loads were not 
invalidated after type mutation.
diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c
index c12a4f4131bc7e..39dc4877af8884 100644
--- a/Python/optimizer_bytecodes.c
+++ b/Python/optimizer_bytecodes.c
@@ -226,6 +226,10 @@ dummy_func(void) {
             }
             else {
                 sym_set_const(owner, type);
+                if ((((PyTypeObject *)type)->tp_flags & 
Py_TPFLAGS_IMMUTABLETYPE) == 0) {
+                    PyType_Watch(TYPE_WATCHER_ID, type);
+                    _Py_BloomFilter_Add(dependencies, type);
+                }
             }
         }
     }
diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h
index 2db2c87cb3610b..746653906874b5 100644
--- a/Python/optimizer_cases.c.h
+++ b/Python/optimizer_cases.c.h
@@ -2571,6 +2571,10 @@
                 }
                 else {
                     sym_set_const(owner, type);
+                    if ((((PyTypeObject *)type)->tp_flags & 
Py_TPFLAGS_IMMUTABLETYPE) == 0) {
+                        PyType_Watch(TYPE_WATCHER_ID, type);
+                        _Py_BloomFilter_Add(dependencies, type);
+                    }
                 }
             }
             break;

_______________________________________________
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