From: Furkan Önder Date: Fri, 5 Jun 2020 19:56:32 +0000 (+0300) Subject: bpo-19468: delete unnecessary instance check in importlib.reload() (GH-19424) X-Git-Tag: v3.10.0a1~713 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fef1fae9df3b03510f9defb25bd0388135b4c591;p=thirdparty%2FPython%2Fcpython.git bpo-19468: delete unnecessary instance check in importlib.reload() (GH-19424) Automerge-Triggered-By: @brettcannon --- diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py index 0c73c505f98d..bea37d766262 100644 --- a/Lib/importlib/__init__.py +++ b/Lib/importlib/__init__.py @@ -54,7 +54,6 @@ _unpack_uint32 = _bootstrap_external._unpack_uint32 # Fully bootstrapped at this point, import whatever you like, circular # dependencies and startup overhead minimisation permitting :) -import types import warnings @@ -136,12 +135,13 @@ def reload(module): The module must have been successfully imported before. """ - if not module or not isinstance(module, types.ModuleType): - raise TypeError("reload() argument must be a module") try: name = module.__spec__.name except AttributeError: - name = module.__name__ + try: + name = module.__name__ + except AttributeError: + raise TypeError("reload() argument must be a module") if sys.modules.get(name) is not module: msg = "module {} not in sys.modules" diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-05-30-23-18-35.bpo-19468.S-TA7p.rst b/Misc/NEWS.d/next/Core and Builtins/2020-05-30-23-18-35.bpo-19468.S-TA7p.rst new file mode 100644 index 000000000000..e35750e37f4d --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-05-30-23-18-35.bpo-19468.S-TA7p.rst @@ -0,0 +1,2 @@ +Delete unnecessary instance check in importlib.reload(). +Patch by Furkan Önder.