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:
parent
236d746c5e
commit
00bd3a553c
2 changed files with 6 additions and 1 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue