[PATCH] import-checker: recognize relative imports from parents of current package

Yuya Nishihara yuya at tcha.org
Mon May 9 09:20:29 EDT 2016


On Sat, 07 May 2016 20:02:08 +0200, liscju wrote:
> # HG changeset patch
> # User liscju <piotr.listkiewicz at gmail.com>
> # Date 1462643970 -7200
> #      Sat May 07 19:59:30 2016 +0200
> # Branch stable
> # Node ID 8d94af1016c999d2dca0368fb593d72dfd6ee81d
> # Parent  f85de28eae32e7d3064b1a1321309071bbaaa069
> import-checker: recognize relative imports from parents of current package

Looks fine, pushed to the committed repo, thanks.

> @@ -140,8 +146,12 @@ def fromlocalfunc(modulename, localmods)
>              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]

I assume level < len(modulename.split('.')) otherwise import would fail at
run time.


More information about the Mercurial-devel mailing list