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-112066: Add `PyDict_SetDefaultRef` function. by colesbury · Pull Request #112123 · python/cpython Conversation
|
|
cc @zooba, @encukou, and @serhiy-storchaka in case you are interested in this |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
My only comment is the same as for the recently added pop functions: we should not use these functions as precedent for their API design (specifically how the return value is handled). When we come to decide which approach we want to standardise for the C API in general, we aren't going to be forced into choosing this design just because it was used during the period between deciding-to-decide and actually deciding. But since there's a chance that the other recently added API could also become "warts", best to align with those since they're all on the same type. There's nothing gained by deliberate inconsistency when the functions show up right next to each other. |
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.
Very nice. The code looks good.
But I worry that all exit branches simply add Py_NewRef() for PyDict_SetDefaultRef(). It means that PyDict_SetDefaultRef() is not principally different from PyDict_SetDefault() combined with Py_XNewRef(). The question arises about the need to add a new function.
Could you please create a separate PR that replaces all PyDict_SetDefault() with PyDict_SetDefaultRef() to show what benefit it could bring.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
IMO, if the C-API WG is formed and decides soon enough, this API and all its uses in CPython might be adjusted. That might affect in-flight PRs.
With nogil, the latter is incorrect. The reference can become invalid (and the object deallocated) between the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: Petr Viktorin <[email protected]>
|
As @encukou wrote, returning a strong reference is important in nogil builds and can't be safely simulated with a subsequent I'll put up a subsequent PR that replaces internal |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@serhiy-storchaka - here is an example PR that changes usages: #112211. When this PR lands, I'll rebase that PR on top of it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Are there any outstanding concerns with this change @encukou @serhiy-storchaka? |
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.
Thank you for #112211 (yet one nice number!).
Please add a What's New entry. The rest LGTM.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I've added the "What's New" entry |
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.
LGTM.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@serhiy-storchaka - would you please merge this? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Provided for consideration of the C API WG: capi-workgroup/decisions#4. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Looks like the C API WG approved the API. @serhiy-storchaka, can we merge this PR now? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
One more issue needs to be resolved. Wait another week. 😉 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The issue I was talking about was the ongoing vote to promote @colesbury as a core developer. I think it would be nice if Sam merge his PR himself. Welcome on the board! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The `PyDict_SetDefaultRef` function is similar to `PyDict_SetDefault`, but returns a strong reference through the optional `**result` pointer instead of a borrowed reference. Co-authored-by: Petr Viktorin <[email protected]>
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.