Repository navigation
[C API] Add PyImport_ImportModuleAttr(mod_name, attr_name) helper function #128911
Copy link
Copy link
Closed
Labels
Description
Activity
- addedtype-featureA feature request or enhancementA feature request or enhancement
on Jan 16, 2025 - added a commit that references this issue
on Jan 16, 2025 IMO, the
*Stringfunctions should generally have variants that takePyObject*.
So, if we add this we should also addPyImport_GetModuleAttr.Reacted by Erlend E. Aasland and Bénédikt TranSo, if we add this we should also add PyImport_GetModuleAttr.
Ok, I added PyImport_GetModuleAttr() to my PR.
- added 4 commits that reference this issue
on Jan 17, 2025 This sounds like a useful addition. The fact that the internal API is already used a lot in CPython is evidence enough 😄
And BTW: I like that you're starting to approach C API design from the perspective of a C programmer again.
Rich C APIs make it a joy programming against them, while minimalist APIs only result in others creating additional layers on top, which adds fragmentation, overall increased maintenance and loss of design control. 👍
- changed the title
[-][C API] Add PyImport_GetModuleAttrString(mod_name, attr_name) helper function[/-][+][C API] Add PyImport_ImportModuleAttr(mod_name, attr_name) helper function[/+]on Jan 26, 2025 See also #129367 which proposes adding
PySys_GetAttr().
Feature or enhancement
Proposal:
Python has an internal
_PyImport_GetModuleAttrString(mod_name, attr_name)helper function to import a module and get a module attribute. I propose to make this function public to be able to use it outside Python.UPDATE: Function renamed to
PyImport_ImportModuleAttrString().The function is convenient to use and is used by the following files in Python:
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs