Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/editables/redirector.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ def map_module(cls, name: str, path: str) -> None:
def find_spec(
cls, fullname: str, path: ModulePath = None, target: Optional[ModuleType] = None
) -> Optional[importlib.machinery.ModuleSpec]:
if "." in fullname:
return None
if path is not None:
return None
try:
redir = cls._redirections[fullname]
except KeyError:
Expand Down
24 changes: 24 additions & 0 deletions tests/test_redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,30 @@ def test_redirects(tmp_path):
assert pkg.sub.val == 42


def test_namespace_redirects(tmp_path):
project = tmp_path / "project"
project_files = {
"ns.pkg": {
"__init__.py": "val = 42",
"sub.py": "val = 42",
}
}
build(project, project_files)

# Redirector is not responsible for ensuring that "ns" exists
build(tmp_path / "site-packages", {"ns": {}})

with save_import_state():
sys.path.append(str(tmp_path / "site-packages"))
F.install()
F.map_module("ns.pkg", project / "ns.pkg" / "__init__.py")

import ns.pkg.sub

assert ns.pkg.val == 42
assert ns.pkg.sub.val == 42


def test_cache_invalidation():
F.install()
# assert that the finder matches importlib's expectations
Expand Down