Skip to content

Commit

Permalink
Avoid reloading builtin types module.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Feb 21, 2017
1 parent 842faa9 commit aaaedbd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion IPython/lib/deepreload.py
Expand Up @@ -39,6 +39,7 @@

from types import ModuleType
from warnings import warn
import types

original_import = builtin_mod.__import__

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

return result, next, buf


# Need to keep track of what we've already reloaded to prevent cyclic evil
found_now = {}

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

def deep_reload_hook(m):
"""Replacement for reload()."""
# Hardcode this one as it would raise a NotImplemeentedError from the
# bowels of Python and screw up the import machinery after.
# unlike other imports the `exclude` list aleady in place is not enough.

if m is types:
return m
if not isinstance(m, ModuleType):
raise TypeError("reload() argument must be module")

Expand Down Expand Up @@ -319,7 +327,7 @@ def deep_reload_hook(m):
return newm

# Save the original hooks
original_reload = imp.reload # Python 3
original_reload = imp.reload

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

0 comments on commit aaaedbd

Please sign in to comment.