Skip to content
Merged
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: 2 additions & 2 deletions src/codegraph/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def query_dependents(store: IndexStore, module: str, limit: int = 200):
for r in rows]
seen = {r["path"] for r in results}
mod = file["module"] or ""
if "." in mod:
base, name = mod.rsplit(".", 1)
if mod:
base, _, name = mod.rpartition(".")
# Match plain JSON tokens with instr(); for aliases, normalize JSON's
# escaped tabs and use GLOB so arbitrary spaces/tabs around ``as``
# work. Relative imports (module ".") count too when the importing
Expand Down
18 changes: 18 additions & 0 deletions tests/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,24 @@ def test_dependents_via_relative_import(self):
finally:
store.close()

def test_dependents_via_top_level_relative_import(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
(root / "__init__.py").write_text(
"from . import sibling\n", encoding="utf-8")
(root / "sibling.py").write_text(
"def deliver(item):\n return item\n", encoding="utf-8")
cfg = load_config(root=str(root))
cfg.engine = "quick"
build_index(cfg)
store = IndexStore(str(cfg.db_path))
try:
rows = query_dependents(store, "sibling")
self.assertEqual(
[row["path"] for row in rows], ["__init__.py"])
finally:
store.close()

def test_relative_import_does_not_match_package_prefix(self):
"""A sibling package with a shared prefix is not a dependent."""
with tempfile.TemporaryDirectory() as tmp:
Expand Down
Loading