GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||
GeezerVison is showing github.com — gh-141510: Add PyAnyDict_AsNewDict() function by vstinner · Pull Request #145531 · python/cpython Conversation
|
|
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) { goto error; } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
What's the motivation for this change? Would something like
That's for a vote; I can't speak for the entire WG. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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) { goto error; } if (PyDict_Merge(dict, orig_dict, 1) < 0) { Py_DECREF(dict); goto error; } } else { dict = PyDict_Copy(orig_dict); if (dict == NULL) { goto error; } } 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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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 def adjust_frozendict(data: frozendict) -> frozendict: mutable = dict(data) mutable["whatever"] = 123 return frozendict(mutable) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ok, I renamed the function to
Yes, call |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Currently, |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I lost track of this function and Python 3.15 beta1 has been released without it. We are now past the feature freeze, so I don't think that it's worth it to add such function. We can revisit this function later if there is a need for it. I close th PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.