Skip to content

Add bindings for PyDict_SetDefaultRef and use them in PyCode::run#5955

Open
ngoldbaum wants to merge 5 commits intoPyO3:mainfrom
ngoldbaum:globals-set-default
Open

Add bindings for PyDict_SetDefaultRef and use them in PyCode::run#5955
ngoldbaum wants to merge 5 commits intoPyO3:mainfrom
ngoldbaum:globals-set-default

Conversation

@ngoldbaum
Copy link
Copy Markdown
Contributor

@ngoldbaum ngoldbaum commented Apr 6, 2026

While experimenting with a build of PyO3 that supports PEP 803 without using critical sections, I noticed that the use in PyCode::run can be replaced by PyDict_SetDefaultRef. This also makes the implementation a lot simpler.

I added bindings for that function on 3.13 and newer and 3.15 and newer in the limited API. I also added a compat shim based on the implementation in pythoncapi-compat: https://github.com/python/pythoncapi-compat/blob/75a796764d63327268d195e2d5c044e564d0dada/pythoncapi_compat.h#L1314.

@ngoldbaum ngoldbaum force-pushed the globals-set-default branch from 69e4dab to 13a0dc4 Compare April 6, 2026 20:07
@ngoldbaum ngoldbaum marked this pull request as ready for review April 6, 2026 20:33
@ngoldbaum
Copy link
Copy Markdown
Contributor Author

It looks like we don't have extensive coverage tests for our compat shims. Maybe we should? I'd prefer not to add infrastructure for that in this PR though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant