Mercurial > hg
changeset 29122:660d8d4ec7aa
import-checker: recognize relative imports from parents of current package
So far fromlocal recognizes relative imports of the form:
from . import D
from .. import E
It wasn't prepared for recognizing relative imports like:
from ..F import G
The bug was not found so far because all relative imports starting
from the parent was in the list of allowsymbolicimports like:
from ..i18n import
from ..node import
author | liscju <piotr.listkiewicz@gmail.com> |
---|---|
date | Sat, 07 May 2016 19:59:30 +0200 |
parents | dc406c7e41d6 |
children | 0e6b5a5aca22 |
files | contrib/import-checker.py |
diffstat | 1 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/import-checker.py Fri May 06 21:44:41 2016 +0530 +++ b/contrib/import-checker.py Sat May 07 19:59:30 2016 +0200 @@ -126,9 +126,15 @@ False >>> fromlocal(None, 1) ('foo', 'foo.__init__', True) + >>> fromlocal('foo1', 1) + ('foo.foo1', 'foo.foo1', False) >>> fromlocal2 = fromlocalfunc('foo.xxx.yyy', localmods) >>> fromlocal2(None, 2) ('foo', 'foo.__init__', True) + >>> fromlocal2('bar2', 1) + False + >>> fromlocal2('bar', 2) + ('foo.bar', 'foo.bar.__init__', True) """ prefix = '.'.join(modulename.split('.')[:-1]) if prefix: @@ -140,8 +146,12 @@ assert level > 0 candidates = ['.'.join(modulename.split('.')[:-level])] else: - # Check relative name first. - candidates = [prefix + name, name] + if not level: + # Check relative name first. + candidates = [prefix + name, name] + else: + candidates = ['.'.join(modulename.split('.')[:-level]) + + '.' + name] for n in candidates: if n in localmods: