Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aaaedbd

Browse files
committed
Avoid reloading builtin types module.
Closes #10235
1 parent 842faa9 commit aaaedbd

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

IPython/lib/deepreload.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
from types import ModuleType
4141
from warnings import warn
42+
import types
4243

4344
original_import = builtin_mod.__import__
4445

@@ -162,6 +163,7 @@ def load_next(mod, altmod, name, buf):
162163

163164
return result, next, buf
164165

166+
165167
# Need to keep track of what we've already reloaded to prevent cyclic evil
166168
found_now = {}
167169

@@ -269,6 +271,12 @@ def deep_import_hook(name, globals=None, locals=None, fromlist=None, level=-1):
269271

270272
def deep_reload_hook(m):
271273
"""Replacement for reload()."""
274+
# Hardcode this one as it would raise a NotImplemeentedError from the
275+
# bowels of Python and screw up the import machinery after.
276+
# unlike other imports the `exclude` list aleady in place is not enough.
277+
278+
if m is types:
279+
return m
272280
if not isinstance(m, ModuleType):
273281
raise TypeError("reload() argument must be module")
274282

@@ -319,7 +327,7 @@ def deep_reload_hook(m):
319327
return newm
320328

321329
# Save the original hooks
322-
original_reload = imp.reload # Python 3
330+
original_reload = imp.reload
323331

324332
# Replacement for reload()
325333
def reload(module, exclude=('sys', 'os.path', 'builtins', '__main__',

0 commit comments

Comments
 (0)