Show More
@@ -143,6 +143,16 b' def _demandimport(name, globals=None, lo' | |||
|
143 | 143 | # The modern Mercurial convention is to use absolute_import everywhere, |
|
144 | 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 | 156 | if level >= 0: |
|
147 | 157 | # Mercurial's enforced import style does not use |
|
148 | 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 | 164 | fromlist, level) |
|
155 | 165 | |
|
156 | 166 | mod = _hgextimport(_origimport, name, globals, locals, level=level) |
|
167 | ||
|
157 | 168 | for x in fromlist: |
|
158 | # Missing symbols mean they weren't defined in the module | |
|
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)) | |
|
169 | processfromitem(mod, x, level=level) | |
|
163 | 170 | |
|
164 | 171 | return mod |
|
165 | 172 | |
@@ -172,10 +179,10 b' def _demandimport(name, globals=None, lo' | |||
|
172 | 179 | setattr(mod, comp, |
|
173 | 180 | _demandmod(comp, mod.__dict__, mod.__dict__)) |
|
174 | 181 | mod = getattr(mod, comp) |
|
182 | ||
|
175 | 183 | for x in fromlist: |
|
176 | # set requested submodules for demand load | |
|
177 | if getattr(mod, x, nothing) is nothing: | |
|
178 | setattr(mod, x, _demandmod(x, mod.__dict__, locals)) | |
|
184 | processfromitem(mod, x) | |
|
185 | ||
|
179 | 186 | return mod |
|
180 | 187 | |
|
181 | 188 | ignore = [ |
General Comments 0
You need to be logged in to leave comments.
Login now