Fix accidental module aliasing

When there was no top-level module or package available in sys.path
(like pylab), but there was a different module/package that was a prefix
of the first module (like py), findimports would incorrectly decide that
they were one and the same!

Fixes #10.
This commit is contained in:
Marius Gedminas 2019-10-31 21:55:13 +02:00
parent 236d746c5e
commit 00bd3a553c
2 changed files with 6 additions and 1 deletions

View file

@ -518,7 +518,7 @@ class ModuleGraph(object):
candidate = self.isPackage(name, extrapath)
if candidate:
return candidate
name = name[:name.rfind('.')]
name = name.rpartition('.')[0]
self.warn(dotted_name, '%s: could not find %s', filename, dotted_name)
return dotted_name

View file

@ -19,7 +19,12 @@ We print warnings when we cannot find a module/package
... import imaginary.package
... ''')
>>> with open('foo.py', 'w') as f: _ = f.write('''
... # decoy, see https://github.com/mgedmin/findimports/issues/10
... ''')
>>> graph = ModuleGraph()
>>> graph.path.append('.')
>>> graph.parseFile('marmalade.py')
marmalade.py: could not find foobar
marmalade.py: could not find imaginary.package