-
Notifications
You must be signed in to change notification settings - Fork 85
Don't automatically add PyInit_<name> to export symbols in Python 3.15+ #395
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
Since PEP 793, it's valid for modules to not have a PyInit function. Telling MSVC to export a nonexistent function will make it fail. The function should be exported in code, using `PyMODINIT_FUNC` (which adds `__declspec(dllexport)`, which is preferred over `/EXPORT` according to [Microsoft docs].) Microsoft docs: https://learn.microsoft.com/en-us/cpp/build/reference/export-exports-a-function?view=msvc-170
rgommers
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.
This implementation looks good to me, for now I only have a few very small suggestions for the docstring. I still need to do some testing with a few real-world packages.
For other reviewers: this relies on python/cpython#141672, which was merged only last week.
| import hook function. | ||
| Since Python 3.15, don't add anything. | ||
| An export directive should be in the code itself. |
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 original could possibly confuse the reader, since it could be read as
the package author having to do something - so try to rephrase:
| An export directive should be in the code itself. | |
| An export directive was added to the "PyMODINIT_FUNC" implementation | |
| for Python 3.15, which is all that is needed. |
| export. This returns, and possibly updates, 'ext.export_symbols'. | ||
| On Python 3.14 and below (that is, before a new export hook name was added), | ||
| it adds "PyInit_" + module_name 'ext.export_symbols'. |
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.
| it adds "PyInit_" + module_name 'ext.export_symbols'. | |
| it adds "PyInit_" + module_name to 'ext.export_symbols'. |
|
I tested this change with the With the latest released version of After applying the patch in this PR to That repo uses test packages with I then started with I then also added a new Testing on 3.15-alpha is pretty cumbersome given the many packaging components and packages that don't yet support 3.15. That said, I'm confident that this PR works, and the testing I was able to do all worked as expected - so I'm +1 for merging this PR. |
Since PEP 793, it's valid for modules to not have a PyInit function. Telling MSVC to export a nonexistent function will make it fail.
The function should be exported in code, using
PyMODINIT_FUNC(which adds__declspec(dllexport), which is preferred over/EXPORTaccording to Microsoft docs.)Fixes: #387