GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add C API for importing an attribute from a module · Issue #93741 · python/cpython

Add C API for importing an attribute from a module #93741

New issue
Copy link
New issue
Copy link
Closed
#93742
Closed
Add C API for importing an attribute from a module#93741
#93742
Copy link
Labels
topic-C-APItype-featureA feature request or enhancementA feature request or enhancement

Description

@serhiy-storchaka
serhiy-storchaka
opened on Jun 12, 2022
Issue body actions

It is common (more than 30 cases) in the C code to access a function or a variable from other module. For example:

    functools = PyImport_ImportModule("functools");
    if (!functools)
        goto error;
    st->partial = PyObject_GetAttrString(functools, "partial");
    Py_CLEAR(functools);

I propose to add a private helper function which combines PyImport_ImportModule() and PyObject_GetAttrString().

    st->partial = _PyImport_GetModuleAttrString("functools", "partial");

It will save 4-6 lines of code and a variable on every use.

Activity

  1. serhiy-storchaka
    added
    type-featureA feature request or enhancementA feature request or enhancement
    topic-C-API
    on Jun 12, 2022
  2. serhiy-storchaka
    added a commit that references this issue on Jun 12, 2022

    pythongh-93741: Add private C API _PyImport_GetModuleAttrString()

    619cba1
  3. kumaraditya303 commented on Jun 13, 2022

    @kumaraditya303
    kumaraditya303
    on Jun 13, 2022
    Contributor
    More actions

    Since this will be private API, how about using statically allocated string identifiers to avoid memory allocations?

    Reacted by Petr Viktorin
  4. serhiy-storchaka commented on Jun 13, 2022

    @serhiy-storchaka
    serhiy-storchaka
    on Jun 13, 2022
    MemberAuthor
    More actions

    The PR adds also function _PyImport_GetModuleAttr() which takes PyObject* arguments. You can use it with statically allocated string identifiers.

  5. serhiy-storchaka
    closed this as completedin #93742on Jun 14, 2022
  6. serhiy-storchaka
    added 5 commits that reference this issue on Jun 14, 2022

    gh-93741: Add private C API _PyImport_GetModuleAttrString() (GH-93742)

    6fd4c8e

    [3.11] pythongh-93741: Add private C API _PyImport_GetModuleAttrStrin…

    96c4a2c

    [3.11] gh-93741: Add private C API _PyImport_GetModuleAttrString() (G…

    d42b368
  7. miss-islington
    added 2 commits that reference this issue on Jun 16, 2022

    [3.11] pythongh-93741: Add private C API _PyImport_GetModuleAttrStrin…

    23e45dd

    [3.11] gh-93741: Add private C API _PyImport_GetModuleAttrString() (G…

    968b238
  8. serhiy-storchaka
    added a commit that references this issue on Jun 26, 2022

    Revert 30935 defer bpo45162 to 312 (#94285)

    1ffde3e
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

    topic-C-APItype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.