Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-128911: Add PyImport_ImportModuleAttr() function#128912
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
vstinner commented Jan 16, 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.
Remove "pycore_import.h" includes, no longer needed.
vstinner commented Jan 16, 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.
|
* Add Modules/_testlimitedcapi/import.c * Add Lib/test/test_capi/test_import.py
vstinner commented Jan 16, 2025
I wrote #128915 to add these tests first. |
vstinner commented Jan 17, 2025
Done, I added tests. |
Uh oh!
There was an error while loading. Please reload this page.
corona10 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.
looks good to me.
vstinner commented Jan 19, 2025
I created a C API Working Group decision issue: capi-workgroup/decisions#53 |
Lib/test/test_capi/test_import.py Outdated
| # CRASHES execute_code_func(name, NULL, NULL, NULL) | ||
| def check_getmoduleattr(self, getmoduleattr): | ||
| self.assertIs(getmoduleattr('sys', 'argv'), sys.argv) |
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.
Check also a module name containing dots.
Check errors:
- non-existent module
- relative module name
- non-existent attribute
- attribute name containing dots
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.
I added requested tests.
attribute name containing dots
getmoduleattr('sys', 'implementation.name') raises an AttributeError. I prefer to not implement "nested" getattr(). One should write getmoduleattr('sys', 'implementation') + PyObject_GetAttrString(attr, "name").
Uh oh!
There was an error while loading. Please reload this page.
vstinner commented Jan 26, 2025
I renamed the function to |
serhiy-storchaka 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.
LGTM! 👍
vstinner commented Jan 29, 2025
The C API Working Group approved the PyImport_ImportModuleAttr() API. |
3bebe46 into python:mainUh oh!
There was an error while loading. Please reload this page.
vstinner commented Jan 30, 2025
Merged, thanks for reviews! |
) Add PyImport_ImportModuleAttr() and PyImport_ImportModuleAttrString() functions. * Add unit tests. * Replace _PyImport_GetModuleAttr() with PyImport_ImportModuleAttr(). * Replace _PyImport_GetModuleAttrString() with PyImport_ImportModuleAttrString(). * Remove "pycore_import.h" includes, no longer needed.
Remove "pycore_import.h" includes, no longer needed.
📚 Documentation preview 📚: https://cpython-previews--128912.org.readthedocs.build/