You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PyCapsule_Import fails when name is in the form 'package.module.capsule' #76595
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=Noneclosed_at=Nonecreated_at=<Date2017-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=<Date2018-05-17.13:34:57.066>user='https://github.com/lekma'
PR 4988 will break the case 'module.attr.capsule' if 'module.attr' is not a module.
lekma commented on Dec 24, 2017
lekmamannequin
MannequinAuthor
More actions
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?
lekma commented on Apr 30, 2018
lekmamannequin
MannequinAuthor
More actions
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?
"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.
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 ":".
skrah commented on May 16, 2018
skrahmannequin
Mannequin
More actions
I'm sorry if this interrupts the discussion, but isn't this
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.
Activity
lekma commentedon Dec 23, 2017
When capsule name is in the form 'package.module.capsule', PyCapsule_Import fails with an AttributeError (module is never an attribute of package).
serhiy-storchaka commentedon Dec 24, 2017
PR 4988 will break the case 'module.attr.capsule' if 'module.attr' is not a module.
lekma commentedon Dec 24, 2017
lekma commentedon Apr 30, 2018
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?
encukou commentedon May 2, 2018
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.
ncoghlan commentedon May 3, 2018
"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.
ericsnowcurrently commentedon May 15, 2018
+1 on using ":" as the separator.
serhiy-storchaka commentedon May 16, 2018
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 ":".
skrah commentedon May 16, 2018
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.
skrah commentedon May 16, 2018
Ah, Serhiy stated the reason (module already imported) previously. Sorry for the noise.
serhiy-storchaka commentedon May 16, 2018
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.
encukou commentedon May 16, 2018
Is "package.module:namespace.attribute" worth supporting? I guess it isn't, at least for now. So Serhyi's patch will work.
12 remaining items
[3.13] gh-76595: Add note on `PyCapsule_Import` behavior (GH-134022) (G…
[3.14] gh-76595: Add note on `PyCapsule_Import` behavior (GH-134022) (G…
pythongh-76595: Add note on `PyCapsule_Import` behavior (pythonGH-134022
pythongh-76595: Add note on `PyCapsule_Import` behavior (pythonGH-134022
pythongh-76595: Add note on `PyCapsule_Import` behavior (pythonGH-134022
pythongh-76595: Add note on `PyCapsule_Import` behavior (pythonGH-134022
gh-76595: Add tests for PyCapsule_Import() (GH-154588)
pythongh-76595: Use PyObject_GetOptionalAttrString() in PyCapsule_Imp…
[3.13] gh-76595: Add tests for PyCapsule_Import() (GH-154588) (GH-154621
[3.15] gh-76595: Add tests for PyCapsule_Import() (GH-154588) (GH-154619
[3.14] gh-76595: Add tests for PyCapsule_Import() (GH-154588) (GH-154620
gh-76595: PyCapsule_Import() now imports submodules if needed (GH-6898)
pythongh-76595: Add tests for PyCapsule_Import() (pythonGH-154588)
pythongh-76595: PyCapsule_Import() now imports submodules if needed (p…