Mercurial > public > mercurial-scm > hg
comparison mercurial/demandimport.py @ 9315:fb66a7d3f28f
dispatch: also pass level argument to __import__ for ignored modules
I wanted to check if mercurial.demandimport could speed up the loading of
PyObjC, and ran into this: the level argument for __import__, available in
Python 2.5 and later, is silently dropped when doing an 'import *'. I have no
idea what these arguments mean, but this minor change made it work.
(Oh, and because of that 'from ... import *', PyObjC still took about 2s...)
author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
---|---|
date | Wed, 05 Aug 2009 17:19:37 +0200 |
parents | 46293a0c7e9f |
children | ffeaf5ba25d8 |
comparison
equal
deleted
inserted
replaced
9314:3f93f6838639 | 9315:fb66a7d3f28f |
---|---|
79 setattr(self._module, attr, val) | 79 setattr(self._module, attr, val) |
80 | 80 |
81 def _demandimport(name, globals=None, locals=None, fromlist=None, level=None): | 81 def _demandimport(name, globals=None, locals=None, fromlist=None, level=None): |
82 if not locals or name in ignore or fromlist == ('*',): | 82 if not locals or name in ignore or fromlist == ('*',): |
83 # these cases we can't really delay | 83 # these cases we can't really delay |
84 return _origimport(name, globals, locals, fromlist) | 84 if level is None: |
85 return _origimport(name, globals, locals, fromlist) | |
86 else: | |
87 return _origimport(name, globals, locals, fromlist, level) | |
85 elif not fromlist: | 88 elif not fromlist: |
86 # import a [as b] | 89 # import a [as b] |
87 if '.' in name: # a.b | 90 if '.' in name: # a.b |
88 base, rest = name.split('.', 1) | 91 base, rest = name.split('.', 1) |
89 # email.__init__ loading email.mime | 92 # email.__init__ loading email.mime |