Skip to content

[C API] Add PyImport_ImportModuleAttr(mod_name, attr_name) helper function #128911

Description

@vstinner

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:

  • Modules/arraymodule.c
  • Modules/cjkcodecs/cjkcodecs.h
  • Modules/_ctypes/callbacks.c
  • Modules/_datetimemodule.c
  • Modules/_decimal/_decimal.c
  • Modules/_elementtree.c
  • Modules/faulthandler.c
  • Modules/_lsprof.c
  • Modules/_operator.c
  • Modules/_pickle.c
  • Modules/posixmodule.c
  • Modules/selectmodule.c
  • Modules/_sqlite/connection.c
  • Modules/_sqlite/module.c
  • Modules/_sre/sre.c
  • Modules/timemodule.c
  • Modules/_zoneinfo.c
  • Objects/abstract.c
  • Objects/fileobject.c
  • Objects/memoryobject.c
  • Parser/pegen.c
  • Parser/tokenizer/file_tokenizer.c
  • Python/import.c
  • Python/pylifecycle.c

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions