From: Ezio Melotti Date: Sat, 10 Aug 2013 17:01:43 +0000 (+0300) Subject: #18681: merge with 3.3. X-Git-Tag: v3.4.0a2~258 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fbcf4d78c881176345483111503c4bc7765d4ff8;p=thirdparty%2FPython%2Fcpython.git #18681: merge with 3.3. --- fbcf4d78c881176345483111503c4bc7765d4ff8 diff --cc Lib/importlib/__init__.py index d456c48c13b3,22c90f24a7e4..aab54a7f1877 --- a/Lib/importlib/__init__.py +++ b/Lib/importlib/__init__.py @@@ -91,34 -88,3 +91,34 @@@ def import_module(name, package=None) break level += 1 return _bootstrap._gcd_import(name[level:], package, level) + + +_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(parentname), name=parent_name) ++ raise ImportError(msg.format(parent_name), name=parent_name) + return module.__loader__.load_module(name) + finally: + try: + del _RELOADING[name] + except KeyError: + pass diff --cc Misc/NEWS index d504066a6db8,ccbb57a3b863..c79a21bfdec9 --- a/Misc/NEWS +++ 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.