This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mattip
Recipients mattip
Date 2021-03-02.11:41:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1614685283.59.0.727643422908.issue43367@roundup.psfhosted.org>
In-reply-to
Content
If I have a module "parent", and I add another module "child" with a method "f" to it:

child = PyModule_Create(...);
PyModule_AddObject(parent, "child", child);

then I can call 

import parent
parent.child.f()

but importing like this

from parent.child import f

raises a ModuleNotFoundError: ... 'parent' is not a package


This came up in PyTorch https://github.com/pytorch/pytorch/issues/38137 
and in pybind11 https://github.com/pybind/pybind11/issues/2639, 
and in various other places like stackoverflow https://stackoverflow.com/questions/38454852/importerror-with-error-is-not-a-package

A complete example is attached

If this is intentional, it might be nice to emit a warning when calling PyModule_AddObject with a module.
History
Date User Action Args
2021-03-02 11:41:23mattipsetrecipients: + mattip
2021-03-02 11:41:23mattipsetmessageid: <1614685283.59.0.727643422908.issue43367@roundup.psfhosted.org>
2021-03-02 11:41:23mattiplinkissue43367 messages
2021-03-02 11:41:23mattipcreate