Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-113480: Check if the type attribute is really modified before label it modified #113481

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Check if the type attribute is really modified before label it modified
10 changes: 9 additions & 1 deletion Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4960,8 +4960,16 @@ type_setattro(PyObject *self, PyObject *name, PyObject *value)
/* Will fail in _PyObject_GenericSetAttrWithDict. */
Py_INCREF(name);
}

// Get the global dict version of interpreter
// If the version does not change, that means we assigned the same value
// to the attribute, so the type is not modified

PyInterpreterState *interp = _PyInterpreterState_GET();
uint64_t prev_version = interp->dict_state.global_version;

res = _PyObject_GenericSetAttrWithDict((PyObject *)type, name, value, NULL);
if (res == 0) {
if (res == 0 && prev_version != interp->dict_state.global_version) {
/* Clear the VALID_VERSION flag of 'type' and all its
subclasses. This could possibly be unified with the
update_subclasses() recursion in update_slot(), but carefully:
Expand Down