Show More
@@ -143,6 +143,16 b' def _demandimport(name, globals=None, lo' | |||||
143 | # The modern Mercurial convention is to use absolute_import everywhere, |
|
143 | # The modern Mercurial convention is to use absolute_import everywhere, | |
144 | # so modern Mercurial code will have level >= 0. |
|
144 | # so modern Mercurial code will have level >= 0. | |
145 |
|
145 | |||
|
146 | def processfromitem(mod, attr, **kwargs): | |||
|
147 | """Process an imported symbol in the import statement. | |||
|
148 | ||||
|
149 | If the symbol doesn't exist in the parent module, it must be a | |||
|
150 | module. We set missing modules up as _demandmod instances. | |||
|
151 | """ | |||
|
152 | if getattr(mod, attr, nothing) is nothing: | |||
|
153 | setattr(mod, attr, | |||
|
154 | _demandmod(attr, mod.__dict__, locals, **kwargs)) | |||
|
155 | ||||
146 | if level >= 0: |
|
156 | if level >= 0: | |
147 | # Mercurial's enforced import style does not use |
|
157 | # Mercurial's enforced import style does not use | |
148 | # "from a import b,c,d" or "from .a import b,c,d" syntax. In |
|
158 | # "from a import b,c,d" or "from .a import b,c,d" syntax. In | |
@@ -154,12 +164,9 b' def _demandimport(name, globals=None, lo' | |||||
154 | fromlist, level) |
|
164 | fromlist, level) | |
155 |
|
165 | |||
156 | mod = _hgextimport(_origimport, name, globals, locals, level=level) |
|
166 | mod = _hgextimport(_origimport, name, globals, locals, level=level) | |
|
167 | ||||
157 | for x in fromlist: |
|
168 | for x in fromlist: | |
158 | # Missing symbols mean they weren't defined in the module |
|
169 | processfromitem(mod, x, level=level) | |
159 | # itself which means they are sub-modules. |
|
|||
160 | if getattr(mod, x, nothing) is nothing: |
|
|||
161 | setattr(mod, x, |
|
|||
162 | _demandmod(x, mod.__dict__, locals, level=level)) |
|
|||
163 |
|
170 | |||
164 | return mod |
|
171 | return mod | |
165 |
|
172 | |||
@@ -172,10 +179,10 b' def _demandimport(name, globals=None, lo' | |||||
172 | setattr(mod, comp, |
|
179 | setattr(mod, comp, | |
173 | _demandmod(comp, mod.__dict__, mod.__dict__)) |
|
180 | _demandmod(comp, mod.__dict__, mod.__dict__)) | |
174 | mod = getattr(mod, comp) |
|
181 | mod = getattr(mod, comp) | |
|
182 | ||||
175 | for x in fromlist: |
|
183 | for x in fromlist: | |
176 | # set requested submodules for demand load |
|
184 | processfromitem(mod, x) | |
177 | if getattr(mod, x, nothing) is nothing: |
|
185 | ||
178 | setattr(mod, x, _demandmod(x, mod.__dict__, locals)) |
|
|||
179 | return mod |
|
186 | return mod | |
180 |
|
187 | |||
181 | ignore = [ |
|
188 | ignore = [ |
General Comments 0
You need to be logged in to leave comments.
Login now