Show More
@@ -227,10 +227,14 b' def _demandimport(name, globals=None, lo' | |||
|
227 | 227 | # recurse down the module chain, and return the leaf module |
|
228 | 228 | mod = rootmod |
|
229 | 229 | for comp in modname.split('.')[1:]: |
|
230 |
|
|
|
231 | setattr(mod, comp, _demandmod(comp, mod.__dict__, | |
|
232 |
|
|
|
233 |
|
|
|
230 | obj = getattr(mod, comp, nothing) | |
|
231 | if obj is nothing: | |
|
232 | obj = _demandmod(comp, mod.__dict__, mod.__dict__, level=1) | |
|
233 | setattr(mod, comp, obj) | |
|
234 | elif mod.__name__ + '.' + comp in sys.modules: | |
|
235 | # prefer loaded module over attribute (issue5617) | |
|
236 | obj = sys.modules[mod.__name__ + '.' + comp] | |
|
237 | mod = obj | |
|
234 | 238 | return mod |
|
235 | 239 | |
|
236 | 240 | if level >= 0: |
@@ -337,6 +337,23 b' importing with "absolute_import" feature' | |||
|
337 | 337 | > from .legacy import detail as legacydetail |
|
338 | 338 | > EOF |
|
339 | 339 | |
|
340 | Setup package that re-exports an attribute of its submodule as the same | |
|
341 | name. This leaves 'shadowing.used' pointing to 'used.detail', but still | |
|
342 | the submodule 'used' should be somehow accessible. (issue5617) | |
|
343 | ||
|
344 | $ mkdir -p $TESTTMP/extlibroot/shadowing | |
|
345 | $ cat > $TESTTMP/extlibroot/shadowing/used.py <<EOF | |
|
346 | > detail = "this is extlibroot.shadowing.used" | |
|
347 | > EOF | |
|
348 | $ cat > $TESTTMP/extlibroot/shadowing/proxied.py <<EOF | |
|
349 | > from __future__ import absolute_import | |
|
350 | > from extlibroot.shadowing.used import detail | |
|
351 | > EOF | |
|
352 | $ cat > $TESTTMP/extlibroot/shadowing/__init__.py <<EOF | |
|
353 | > from __future__ import absolute_import | |
|
354 | > from .used import detail as used | |
|
355 | > EOF | |
|
356 | ||
|
340 | 357 | Setup extension local modules to be imported with "absolute_import" |
|
341 | 358 | feature. |
|
342 | 359 | |
@@ -429,6 +446,7 b' Setup main procedure of extension.' | |||
|
429 | 446 | > from extlibroot.lsub1.lsub2 import used as lused, unused as lunused |
|
430 | 447 | > from extlibroot.lsub1.lsub2.called import func as lfunc |
|
431 | 448 | > from extlibroot.recursedown import absdetail, legacydetail |
|
449 | > from extlibroot.shadowing import proxied | |
|
432 | 450 | > |
|
433 | 451 | > def uisetup(ui): |
|
434 | 452 | > result = [] |
@@ -436,6 +454,7 b' Setup main procedure of extension.' | |||
|
436 | 454 | > result.append(lfunc()) |
|
437 | 455 | > result.append(absdetail) |
|
438 | 456 | > result.append(legacydetail) |
|
457 | > result.append(proxied.detail) | |
|
439 | 458 | > ui.write('LIB: %s\n' % '\nLIB: '.join(result)) |
|
440 | 459 | > EOF |
|
441 | 460 | |
@@ -446,6 +465,7 b' Examine module importing.' | |||
|
446 | 465 | LIB: this is extlibroot.lsub1.lsub2.called.func() |
|
447 | 466 | LIB: this is extlibroot.recursedown.abs.used |
|
448 | 467 | LIB: this is extlibroot.recursedown.legacy.used |
|
468 | LIB: this is extlibroot.shadowing.used | |
|
449 | 469 | ABS: this is absextroot.xsub1.xsub2.used |
|
450 | 470 | ABS: this is absextroot.xsub1.xsub2.called.func() |
|
451 | 471 | |
@@ -454,6 +474,7 b' Examine module importing.' | |||
|
454 | 474 | LIB: this is extlibroot.lsub1.lsub2.called.func() |
|
455 | 475 | LIB: this is extlibroot.recursedown.abs.used |
|
456 | 476 | LIB: this is extlibroot.recursedown.legacy.used |
|
477 | LIB: this is extlibroot.shadowing.used | |
|
457 | 478 | REL: this is absextroot.xsub1.xsub2.used |
|
458 | 479 | REL: this is absextroot.xsub1.xsub2.called.func() |
|
459 | 480 | REL: this relimporter imports 'this is absextroot.relimportee' |
General Comments 0
You need to be logged in to leave comments.
Login now