Skip to content

gh-135228: Create __dict__ and __weakref__ descriptors for object #136966

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove sys._clear_type_descriptors
  • Loading branch information
encukou committed Aug 12, 2025
commit a71d91a73555cf5ec32b48025c35e1b3411bd5de
33 changes: 1 addition & 32 deletions Python/clinic/sysmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 0 additions & 41 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2641,46 +2641,6 @@ sys__baserepl_impl(PyObject *module)
Py_RETURN_NONE;
}

/*[clinic input]
sys._clear_type_descriptors

type: object(subclass_of='&PyType_Type')
/

Private function for clearing certain descriptors from a type's dictionary.

See gh-135228 for context.
[clinic start generated code]*/

static PyObject *
sys__clear_type_descriptors_impl(PyObject *module, PyObject *type)
/*[clinic end generated code: output=5ad17851b762b6d9 input=dc536c97fde07251]*/
{
PyTypeObject *typeobj = (PyTypeObject *)type;
if (_PyType_HasFeature(typeobj, Py_TPFLAGS_IMMUTABLETYPE)) {
PyErr_SetString(PyExc_TypeError, "argument is immutable");
return NULL;
}
PyObject *dict = _PyType_GetDict(typeobj);
PyObject *dunder_dict = NULL;
if (PyDict_Pop(dict, &_Py_ID(__dict__), &dunder_dict) < 0) {
return NULL;
}
PyObject *dunder_weakref = NULL;
if (PyDict_Pop(dict, &_Py_ID(__weakref__), &dunder_weakref) < 0) {
PyType_Modified(typeobj);
Py_XDECREF(dunder_dict);
return NULL;
}
PyType_Modified(typeobj);
// We try to hold onto a reference to these until after we call
// PyType_Modified(), in case their deallocation triggers somer user code
// that tries to do something to the type.
Py_XDECREF(dunder_dict);
Py_XDECREF(dunder_weakref);
Py_RETURN_NONE;
}


/*[clinic input]
sys._is_gil_enabled -> bool
Expand Down Expand Up @@ -2878,7 +2838,6 @@ static PyMethodDef sys_methods[] = {
SYS__STATS_DUMP_METHODDEF
#endif
SYS__GET_CPU_COUNT_CONFIG_METHODDEF
SYS__CLEAR_TYPE_DESCRIPTORS_METHODDEF
SYS__IS_GIL_ENABLED_METHODDEF
SYS__DUMP_TRACELETS_METHODDEF
{NULL, NULL} // sentinel
Expand Down