ipython / ipython/ipython

dreload can't handle renamed modules

Aperta
#1,660 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug
Lingua principale
Python
Stelle
16.8k
Fork
4.5k
Merge medio
1g 2h
PR unite (30g)
6

Descrizione

Consider the following situation (similar to `os.path`), whereby we manually insert an entry in `sys.modules`.

```
--- A.py ---
import sys
import B
sys.modules['C'] = B
del B
import C

--- B.py ---
pass
```

The current `dreload` cannot handle such a situation. In particular, `dreload(A)` fails because it cannot find the module `C` (as it doesn't actually exist). In this situation, where `C` is in `sys.modules`, should we just return `sys.modules['C']` without complaint?

```
In [6]: dreload(A)
Reloading B
Reloading C
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/home/bfroehle/tm/ in ()
----> 1 dreload(A)

/home/bfroehle/src/ipython/IPython/lib/deepreload.pyc in reload(module, exclude)
329 try:
330 with replace_import_hook(deep_import_hook):
--> 331 ret = deep_reload_hook(module)
332 finally:
333 found_now = {}

/home/bfroehle/src/ipython/IPython/lib/deepreload.pyc in deep_reload_hook(m)
299
300 try:
--> 301 newm = imp.load_module(name, fp, filename, stuff)
302 except:
303 # load_module probably removed name from modules because of

/home/bfroehle/tm/A.pyc in ()
3 sys.modules['C'] = B
4 del B
----> 5 import C

/home/bfroehle/src/ipython/IPython/lib/deepreload.pyc in deep_import_hook(name, globals, locals, fromlist, level)
240 parent, buf = get_parent(globals, level)
241
--> 242 head, name, buf = load_next(parent, None if level < 0 else parent, name, buf)
243
244 tail = head

/home/bfroehle/src/ipython/IPython/lib/deepreload.pyc in load_next(mod, altmod, name, buf)
151
152 if result is None:
--> 153 raise ImportError("No module named %.200s" % name)
154
155 return result, next, buf

ImportError: No module named C
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.