codemap
codemap copied to clipboard
python: 'from pkg import submodule' resolves to __init__.py, 'from . import name' drops the edge
Two related package-member resolution misses:
from pkg import submoduleresolves topkg/__init__.pyinstead ofpkg/submodule.pywhensubmoduleis a module file, not a name defined in__init__.py(yt-dlp:from yt_dlp import socks).from . import name/from .. import name, wherenameis defined in the package's__init__.py, yields no edge at all (spec-kit: 177 of its 260 false negatives target an__init__.py).
Python's rule: for from P import X, X is the submodule P/X.py (or P/X/) if it exists, otherwise a name from P/__init__.py.
Repro (codemap 4.7.0):
pkg/__init__.py: def helper(): pass
pkg/socks.py
use_sub.py: from pkg import socks
pkg/sub/__init__.py: def g(): pass
pkg/sub/child.py: from . import g
codemap --importers pkg/socks.py # none, should be use_sub.py
codemap --importers pkg/sub/__init__.py # none, should be pkg/sub/child.py
Found by the import-accuracy benchmark (#264). Part of #240.