Consider a directory structure like this:
path-one/
mod/
sub1.py
path-two/
mod/
__init__.py
sub2.py
Where path-one and path-two are both import-search-path entries, in that order (e.g. PYTHONPATH=path-one:path-two" should make this happen both for ty and at runtime).
At runtime, a non-namespace package anywhere on the search path takes precedence over a namespace package. This means that with the above setup, import mod.sub1 fails. Despite being first on the search path, path-one/mod is never considered as a candidate for the mod package, because path-two/mod/__init__.py exists.
Given import mod in the above scenario, we do prefer path-two/mod/__init__.py over the path-one/mod namespace package. But we wrongly allow import mod.sub1 to succeed, resolving to the path-one namespace package.
In this particular case, that might seem harmless, but it can cause us to import the wrong thing in some scenarios, and it can lead to some very odd inconsistencies with relative imports, documented in import/workspaces.md. Allowing imports of modules in the "should be ignored" namespace package to just fail would allow our "desperate resolution" to kick in (for imports within that "should be ignored" namespace package) and actually give more consistent behavior.
Consider a directory structure like this:
Where
path-oneandpath-twoare both import-search-path entries, in that order (e.g.PYTHONPATH=path-one:path-two"should make this happen both for ty and at runtime).At runtime, a non-namespace package anywhere on the search path takes precedence over a namespace package. This means that with the above setup,
import mod.sub1fails. Despite being first on the search path,path-one/modis never considered as a candidate for themodpackage, becausepath-two/mod/__init__.pyexists.Given
import modin the above scenario, we do preferpath-two/mod/__init__.pyover thepath-one/modnamespace package. But we wrongly allowimport mod.sub1to succeed, resolving to thepath-onenamespace package.In this particular case, that might seem harmless, but it can cause us to import the wrong thing in some scenarios, and it can lead to some very odd inconsistencies with relative imports, documented in
import/workspaces.md. Allowing imports of modules in the "should be ignored" namespace package to just fail would allow our "desperate resolution" to kick in (for imports within that "should be ignored" namespace package) and actually give more consistent behavior.