gh-141510: Always return a dict in PyDict_Copy()#145517
gh-141510: Always return a dict in PyDict_Copy()#145517vstinner wants to merge 3 commits intopython:mainfrom
Conversation
* PyDict_Copy() now also returns a dict if the argument is a frozendict. * Remove _PyDict_CopyAsDict() function. * Fix frozendict.items() ^ frozendict.items(). Add non-regression test.
|
I propose changing Example in static PyTypeObject*
type_new_init(type_new_ctx *ctx)
{
PyObject *dict = PyDict_Copy(ctx->orig_dict);
if (dict == NULL) {
goto error;
}
...
set_tp_dict(type, dict);
...
}The function accepts Example in static PyObject*
get_attrib_from_keywords(PyObject *kwds)
{
...
if (attrib) {
...
Py_SETREF(attrib, PyDict_Copy(attrib));
}
else {
attrib = PyDict_New();
}
if (attrib != NULL && PyDict_Update(attrib, kwds) < 0) {
Py_DECREF(attrib);
return NULL;
}
return attrib;
}(With my pending change PR gh-145508), the function accepts |
|
Currently, Existing C extensions calling Always returning |
📚 Documentation preview 📚: https://cpython-previews--145517.org.readthedocs.build/