Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-141004: document pyexpat C API#141259
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
base:main
Are you sure you want to change the base?
Conversation
picnixz commented Nov 8, 2025 • edited by github-actions bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by github-actions bot
Uh oh!
There was an error while loading. Please reload this page.
6164db5 to dc77ab0Comparedc77ab0 to 5b857a4Compare
ZeroIntensity 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.
Thanks for working on these!
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| structPyExpat_CAPI{ | ||
| char*magic; /* set to PyExpat_CAPI_MAGIC */ |
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.
Let's avoid making code formatting changes in this PR.
vstinner 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.
The PyExpat capsule is used to access Modules/pyexpat.c functions in Modules/_elementtree.c. I'm not sure that it was intended to be used outside Modules/_elementtree.c.
A code search on PyPI top 15,000 projects (at 2025-09-22) found no matching projects.
In 2020, I moved the Unicode capsule C structure to the internal C API (pycore_ucnhash.h): commit 47e1afd. Then I renamed the PyUnicodeData_CAPSULE_NAME to make it private: commit 84f7382. I expected lot of complains and broken projects, but no one was impacted :-) It went well.
encukou commented Nov 11, 2025
If you need this you should probably use expat directly; the vendored copy is aliased so that it shouldn't conflict. |
vstinner commented Nov 13, 2025
Should we deprecate the pyexpat public capsule, and use a private capsule in elementtree? |
picnixz commented Nov 14, 2025
I don't use this personally so I would prefer deprecating and making it private :') However, while there might not exist public code relying on this, there might exist private one =/. Strictly speaking, there is actually one handler that Python provides and this is |
| included by default by :file:`Python.h`) and ``expat.h`` for Expat. | ||
| To use the C API, consider adding the following code in your extension | ||
| module initilisation function and store the pointer to the C API in |
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.
Typo:
| module initilisation function and store the pointer to the C API in | |
| module initialization function and store the pointer to the C API in |
vstinner commented Nov 23, 2025
That's the purpose of a deprecation over multiple years, communicate that we are going to remove an API, to give users time to report their usage and ask to keep the API and provide a different one. |
picnixz commented Nov 29, 2025 • 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.
Ok, but how do I really deprecate this one? should I just go with a |
encukou commented Dec 1, 2025
Yeah, As is adding docs to hold “porting notes” (i.e. use the Python APIs, or |
The Expat C API does not store a global variable as other C APIs and instead prefer consumers to add both the capsule and the C API pointer in the consumer's state. I don't really llike this but it's probably the best
📚 Documentation preview 📚: https://cpython-previews--141259.org.readthedocs.build/