]> granicus.if.org Git - python/commitdiff
#18681: merge with 3.3.
authorEzio Melotti <ezio.melotti@gmail.com>
Sat, 10 Aug 2013 17:01:43 +0000 (20:01 +0300)
committerEzio Melotti <ezio.melotti@gmail.com>
Sat, 10 Aug 2013 17:01:43 +0000 (20:01 +0300)
1  2 
Lib/importlib/__init__.py
Lib/test/test_imp.py
Misc/NEWS

index d456c48c13b347556edaede89cbe4492c26f7ac9,22c90f24a7e46cecbbc87027a319576d7c32c006..aab54a7f1877dfe045af0837dd7372b047a2f673
@@@ -91,34 -88,3 +91,34 @@@ def import_module(name, package=None)
                  break
              level += 1
      return _bootstrap._gcd_import(name[level:], package, level)
-             raise ImportError(msg.format(parentname), name=parent_name)
 +
 +
 +_RELOADING = {}
 +
 +
 +def reload(module):
 +    """Reload the module and return it.
 +
 +    The module must have been successfully imported before.
 +
 +    """
 +    if not module or not isinstance(module, types.ModuleType):
 +        raise TypeError("reload() argument must be module")
 +    name = module.__name__
 +    if name not in sys.modules:
 +        msg = "module {} not in sys.modules"
 +        raise ImportError(msg.format(name), name=name)
 +    if name in _RELOADING:
 +        return _RELOADING[name]
 +    _RELOADING[name] = module
 +    try:
 +        parent_name = name.rpartition('.')[0]
 +        if parent_name and parent_name not in sys.modules:
 +            msg = "parent {!r} not in sys.modules"
++            raise ImportError(msg.format(parent_name), name=parent_name)
 +        return module.__loader__.load_module(name)
 +    finally:
 +        try:
 +            del _RELOADING[name]
 +        except KeyError:
 +            pass
Simple merge
diff --cc Misc/NEWS
index d504066a6db82a9064d6361e4a1308a5ceb5db51,ccbb57a3b8632e737ef36bd737afacbee78d88cc..c79a21bfdec9dede9b36a66ebea1f5fe85ff548c
+++ b/Misc/NEWS
@@@ -221,8 -64,10 +221,10 @@@ Core and Builtin
  Library
  -------
  
 -- Issue #18681: Fix a NameError in imp.reload() (noticed by Weizhao Li).
++- Issue #18681: Fix a NameError in importlib.reload() (noticed by Weizhao Li).
 -- Issue #8112: xlmrpc.server's DocXMLRPCServer server no longer raises an error
 -  if methods have annotations; it now correctly displays the annotations.
 +- Issue #14323: Expanded the number of digits in the coefficients for the
 +  RGB -- YIQ conversions so that they match the FCC NTSC versions.
  
  - Issue #17998: Fix an internal error in regular expression engine.