Skip to content

PyCapsule_Import fails when name is in the form 'package.module.capsule' #76595

Closed

Description

@lekma
mannequin
BPO 32414
Nosy @ncoghlan, @encukou, @lekma, @skrah, @ericsnowcurrently, @serhiy-storchaka
PRs
  • bpo-32414: use string after the last dot as the capsule name in PyCapsule_Import #4988
  • gh-76595: PyCapsule_Import() now imports submodules if needed. #6898
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2017-12-23.09:47:09.382>
    labels = ['interpreter-core', 'type-bug', '3.8']
    title = "PyCapsule_Import fails when name is in the form 'package.module.capsule'"
    updated_at = <Date 2018-05-17.13:34:57.066>
    user = 'https://github.com/lekma'

    bugs.python.org fields:

    activity = <Date 2018-05-17.13:34:57.066>
    actor = 'ncoghlan'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Interpreter Core']
    creation = <Date 2017-12-23.09:47:09.382>
    creator = 'lekma'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32414
    keywords = ['patch']
    message_count = 15.0
    messages = ['308950', '308990', '308994', '315944', '316079', '316123', '316735', '316794', '316795', '316798', '316799', '316805', '316915', '316923', '316927']
    nosy_count = 6.0
    nosy_names = ['ncoghlan', 'petr.viktorin', 'lekma', 'skrah', 'eric.snow', 'serhiy.storchaka']
    pr_nums = ['4988', '6898']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue32414'
    versions = ['Python 3.8']

    Linked PRs

    Activity

    1. lekma commented on Dec 23, 2017

      lekmamannequin
      MannequinAuthor

      When capsule name is in the form 'package.module.capsule', PyCapsule_Import fails with an AttributeError (module is never an attribute of package).

    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      type-bugAn unexpected behavior, bug, or error
      on Dec 23, 2017
    3. serhiy-storchaka commented on Dec 24, 2017

      @serhiy-storchaka
      Member

      PR 4988 will break the case 'module.attr.capsule' if 'module.attr' is not a module.

    4. lekma commented on Dec 24, 2017

      lekmamannequin
      MannequinAuthor

      PR 4988 will break the case 'module.attr.capsule' if 'module.attr' is
      not a module.
      you are right, but is that a case you would expect in an import
      statement?

    5. lekma commented on Apr 30, 2018

      lekmamannequin
      MannequinAuthor

      thinking out loud here: maybe both behavior can be exposed, i.e. a PyCapsule_Import that would expect a valid import statement and a Py_GetCapsule that would behave more like getattr?

    6. encukou commented on May 2, 2018

      @encukou
      Member

      An option would be to use a colon to separate the module(s) from the attribute(s). The "inspect" module CLI does this, for example:
      https://docs.python.org/3/library/inspect.html#command-line-interface

      $ python3 -m inspect urllib.parse:SplitResult.geturl
          def geturl(self):
              return urlunsplit(self)

      A colon can't appear in an identifier, so the old way can be used if there's no colon in the argument, making this backwards compatible.

    7. ncoghlan commented on May 3, 2018

      @ncoghlan
      Contributor

      "package.module:attribute" is also the syntax used in packaging tools to unambiguously separate the name of the module to be imported from the attribute chain to be looked up within that module: https://packaging.python.org/specifications/entry-points/

      So +1 from me for extending it to this use case as well.

    8. ericsnowcurrently commented on May 15, 2018

      @ericsnowcurrently
      Member

      +1 on using ":" as the separator.

    9. serhiy-storchaka commented on May 16, 2018

      @serhiy-storchaka
      Member

      Using ":" makes the syntax irregular. "package.module:attribute", but "module.attribute". And "package.module.attribute" works too if "package.module" already is imported.

      It is possible to support importing submodules without using ":".

    10. skrah commented on May 16, 2018

      skrahmannequin
      Mannequin

      I'm sorry if this interrupts the discussion, but isn't this

      https://github.com/plures/xnd/blob/06f6dd82dda9c7bca5df30b121b5cd75c6337609/python/xnd/pyxnd.h#L103

      of the form package.module.capsule?

      This works, and I just want to make sure it continues to do so.

    11. skrah commented on May 16, 2018

      skrahmannequin
      Mannequin

      Ah, Serhiy stated the reason (module already imported) previously. Sorry for the noise.

    12. serhiy-storchaka commented on May 16, 2018

      @serhiy-storchaka
      Member

      In your case importing xnd automatically imports xnd._xnd and sets it as an attribute of xnd. This case works now. PR 6898 adds support for cases when a submodule is not imported automatically by importing a package.

    13. encukou commented on May 16, 2018

      @encukou
      Member

      Is "package.module:namespace.attribute" worth supporting? I guess it isn't, at least for now. So Serhyi's patch will work.

    14. 12 remaining items

    15. added 2 commits that reference this issue on Jun 28, 2025
    16. added a commit that references this issue on Jul 11, 2025
    17. added a commit that references this issue on Jul 12, 2025
    18. added a commit that references this issue on Aug 4, 2025
    19. added a commit that references this issue on Aug 19, 2025
    20. added 5 commits that reference this issue on Jul 24, 2026
    21. added a commit that references this issue on Aug 10, 2026
    22. added 2 commits that reference this issue on Aug 14, 2026
    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

      interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions