-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
gh-138098: Clarify strong references in PyDict_Next docs for free-threaded build #138106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-138098: Clarify strong references in PyDict_Next docs for free-threaded build #138106
Conversation
…ee-threaded build
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.
Looks mostly fine, we just need to add links to the terms.
Thanks for the helpful reviews!
Please let me know if anything else needs to be updated ✅ |
The text itself is good now. But the position in the documentation is a bit odd. The note is separated from the other text on free threading. For that reason, I would move the note down a bit. |
"I have tried adding the .. note:: directive in Sphinx multiple times. |
I have fixed the issue, everything seems correct now. Previously the note was not displaying properly at the top, but now it appears correctly at the bottom |
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.
Thanks, this looks good to me.
@eendebakpt As the issue author, are you happy with this? If so, I'll merge this.
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.
Looks good to me. Thanks @PrinceNaroliya
Thanks for the helpful reviews! I’m happy with the changes and everything looks good now. |
Thanks @PrinceNaroliya for the PR, and @ZeroIntensity for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
…he free-threaded build (pythonGH-138106) (cherry picked from commit 9ee0214b5dd982ac9fbe18dcce0e8787456e29af) Co-authored-by: PrinceNaroliya <[email protected]>
GH-138141 is a backport of this pull request to the 3.14 branch. |
This PR updates the documentation of :c:func:
PyDict_Next
to clarify thehandling of references in the free-threaded build.
Currently, the docs mention that
PyDict_Next
is not safe in the free-threadedbuild and suggest using a critical section. However, the returned
pkey
andpvalue
are borrowed references, which are only valid while the criticalsection is held. If they need to be accessed outside of that critical section,
strong references must be created.
This PR adds a
.. note::
block explaining this behavior explicitly, andsuggests using :c:func:
Py_NewRef
to obtain strong references.Rationale
build.
Example of new docs rendering
Thanks!
📚 Documentation preview 📚: https://cpython-previews--138106.org.readthedocs.build/en/138106/c-api/dict.html#c.PyDict_Next