From fef1fae9df3b03510f9defb25bd0388135b4c591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20=C3=96nder?= Date: Fri, 5 Jun 2020 22:56:32 +0300 Subject: [PATCH] bpo-19468: delete unnecessary instance check in importlib.reload() (GH-19424) Automerge-Triggered-By: @brettcannon --- Lib/importlib/__init__.py | 8 ++++---- .../2020-05-30-23-18-35.bpo-19468.S-TA7p.rst | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2020-05-30-23-18-35.bpo-19468.S-TA7p.rst diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py index 0c73c505f98..bea37d76626 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 00000000000..e35750e37f4 --- /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.