Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.2k
gh-141510: Add PyAnyDict_AsNewDict() function#145531
gh-141510: Add PyAnyDict_AsNewDict() function#145531vstinner wants to merge 5 commits intopython:mainfrom
Conversation
* PyDict_Copy() no longer accepts frozendict.* Remove _PyDict_CopyAsDict() function.* Fix frozendict.items() ^ frozendict.items(). Add non-regression test.
vstinner commentedMar 5, 2026
Example of code to copy a PyObject*dict;if (PyFrozenDict_Check(ctx->orig_dict)) {dict=PyFrozenDict_AsDict(ctx->orig_dict); }else {dict=PyDict_Copy(ctx->orig_dict); }if (dict==NULL) { gotoerror; } |
corona10 left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This was not part of PEP, C API WG is fine with the naming?
cc@encukou
encukou commentedMar 5, 2026
What's the motivation for this change? Would something like
That's for a vote; I can't speak for the entire WG. |
vstinner commentedMar 5, 2026
This PR was big, so I merged unrelated changes as separated changes:
@ZeroIntensity convinced me that supporting
When a function using PyObject*dict;if (PyFrozenDict_Check(orig_dict)) {dict=PyDict_New();if (dict==NULL) { gotoerror; }if (PyDict_Merge(dict,orig_dict,1)<0) {Py_DECREF(dict); gotoerror; } }else {dict=PyDict_Copy(orig_dict);if (dict==NULL) { gotoerror; } } I have to copy/paste this code. I would prefer to have a function doing that: convert a
Oh, I prefer this function over @ZeroIntensity: What do you think of adding a new |
ZeroIntensity commentedMar 5, 2026 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I think this will be useful. When 3.15 comes out, there will be plenty of APIs that assume an input dictionary is mutable, and thus can't be used with Is there an east way to convert a dictionary into a defadjust_frozendict(data:frozendict)->frozendict:mutable=dict(data)mutable["whatever"]=123returnfrozendict(mutable) |
vstinner commentedMar 5, 2026
Ok, I renamed the function to
Yes, call |
Uh oh!
There was an error while loading.Please reload this page.
Remove internal _PyDict_CopyAsDict() function.
📚 Documentation preview 📚:https://cpython-previews--145531.org.readthedocs.build/