How to import from a renamed submodule?

Viewed 14

My project requires patching of another project's code. Seems simple enough:

project/
    __init__.py
        from .patched_project import fixed_project
    my_project.py
    patched_project.py
        from .my_project import useful_function
        import other_project as fixed_project
        # use useful_function with fixed_project

In theory, I can now install this package and the fixed_project can be imported via from project import fixed_project (which works without issue).

However, user's have become accustom to performing from other_project import submodule in all their other projects. As such, they would expect to now use from project.fixed_project import submodule. But this results in ModuleNotFoundError. Why? Does python not run the __init__.py and see fixed_project? A solution like:

from project import fixed_project
submodule = fixed_project.submodule

works, but feels unpythonic. Normally, if one can do the above, I would expect that from project.fixed_project import submodule should work. What am I misunderstanding? Is it expected that __init__.py breaks submodule importing of renamed modules with __init__.py? Is there something that I was suppose to add to the __init__.py so that subpackage, subsubpackage, and subsubsubpackage importing could be performed?

0 Answers
Related