[PATCH 2 of 2] demandimport: omit default value of "level" at construction of _demandmod
FUJIWARA Katsunori
foozy at lares.dti.ne.jp
Sun Aug 7 10:59:37 EDT 2016
At Sun, 7 Aug 2016 21:01:06 +0900,
Yuya Nishihara wrote:
>
> On Sat, 06 Aug 2016 22:28:15 +0900, FUJIWARA Katsunori wrote:
> > # HG changeset patch
> > # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> > # Date 1470489873 -32400
> > # Sat Aug 06 22:24:33 2016 +0900
> > # Node ID 6c99f07655feaf18d09e1d5846c54fc8c8223ddc
> > # Parent 1881f4a509a31d88a5db583c6db8d186040eba94
> > demandimport: omit default value of "level" at construction of _demandmod
>
> The series already ninja queued.
>
> > --- a/mercurial/demandimport.py
> > +++ b/mercurial/demandimport.py
> > @@ -64,8 +64,12 @@ def _hgextimport(importfunc, name, globa
> > return importfunc(hgextname, globals, *args, **kwargs)
> >
> > class _demandmod(object):
> > - """module demand-loader and proxy"""
> > - def __init__(self, name, globals, locals, level=level):
> > + """module demand-loader and proxy
> > +
> > + Specify 1 as 'level' argument at construction, to import module
> > + relatively.
> > + """
> > + def __init__(self, name, globals, locals, level):
> > if '.' in name:
> > head, rest = name.split('.', 1)
> > after = [rest]
>
> > @@ -194,10 +198,9 @@ def _demandimport(name, globals=None, lo
> > if symbol is nothing:
> > mn = '%s.%s' % (mod.__name__, attr)
> > if mn in ignore:
> > - importfunc = _origimport
> > + symbol = _origimport(attr, mod.__dict__, locals, level=1)
> > else:
> > - importfunc = _demandmod
> > - symbol = importfunc(attr, mod.__dict__, locals, level=1)
> > + symbol = _demandmod(attr, mod.__dict__, locals, 1)
>
> This change is okay, but unrelated?
>
_demandmod.__init__() requires no optional argument before "level",
but __import__() as originalimport() requires "fromlist" as below:
__import__(name, globals={}, locals={}, fromlist=[], level=-1)
Therefore, just passing "1" as level argument instead of "level=1"
invokes original __import__() with "fromlist=1" :-<
@@ -196,7 +196,7 @@ def _demandimport(name, globals=None, lo
importfunc = _origimport
else:
importfunc = _demandmod
- symbol = importfunc(attr, mod.__dict__, locals, level=1)
+ symbol = importfunc(attr, mod.__dict__, locals, 1)
setattr(mod, attr, symbol)
# Record the importing module references this symbol so we can
----------------------------------------------------------------------
[FUJIWARA Katsunori] foozy at lares.dti.ne.jp
More information about the Mercurial-devel
mailing list