From: Christian Tismer Date: Sat, 8 May 2021 16:06:23 +0200 Subject: py3.10-prep: reset the type cache after feature switching When using feature switching in Python 3.10, there were funny effects where switched and un-switched versions appeared to co-exist. It turned out that we were hit by function caching that is now implemented for the LOAD_ATTR opcode. It was not known that caching would happen at all for PySide classes because we don't use Py_TPFLAGS_VALID_VERSION_TAG. But actually, this flag is used internally by Python to do some optimizations, and we just have to notify the interpreter of type changes by PyType_Modified(). (cherry picked from commit 3a2b7c6f88bba04d8b7ddb571163d23c15c36a4f) --- sources/pyside2/libpyside/feature_select.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sources/pyside2/libpyside/feature_select.cpp b/sources/pyside2/libpyside/feature_select.cpp index 6a21d16..3da7dde 100644 --- a/sources/pyside2/libpyside/feature_select.cpp +++ b/sources/pyside2/libpyside/feature_select.cpp @@ -405,6 +405,8 @@ static inline PyObject *SelectFeatureSet(PyTypeObject *type) if (!SelectFeatureSetSubtype(sub_type, select_id)) break; } + // PYSIDE-1436: Clear all caches for the type and subtypes. + PyType_Modified(type); } return type->tp_dict; }