codemap icon indicating copy to clipboard operation
codemap copied to clipboard

python: 'from <namespace package> import a, b' links every file in the directory

Open JordanCoin opened this issue 1 month ago • 0 comments

from <package> import a, b where <package> is a namespace package (a directory with no __init__.py) produces an edge to every .py file in that directory, not just a.py and b.py.

Found by the import-accuracy benchmark (#264): on AUTOMATIC1111/stable-diffusion-webui this one pattern is 19,215 of the repo's 19,240 false positives and pulls held-out Python precision to 0.261. It is the largest accuracy defect the benchmark found.

Repro (codemap 4.7.0):

modules/{a,b,c,d,e}.py
modules/user.py:  from modules import a, b
codemap --importers modules/c.py   # reports modules/user.py, should be none

Expected: edges to modules/a.py and modules/b.py only (each imported name that is a submodule file).

Part of #240.

JordanCoin avatar Nov 03 '26 18:11 JordanCoin