Skip to content

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

Open
@vstinner

Description

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.

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

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions