gh-125519: Improve traceback if importlib.reload() is called with a non-module object (#125520)

This commit is contained in:
Alex Waygood 2024-10-21 07:53:21 +01:00 committed by GitHub
parent 9256be7ff0
commit c5c21fee7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 1 deletions

View file

@ -103,7 +103,7 @@ def reload(module):
try:
name = module.__name__
except AttributeError:
raise TypeError("reload() argument must be a module")
raise TypeError("reload() argument must be a module") from None
if sys.modules.get(name) is not module:
raise ImportError(f"module {name} not in sys.modules", name=name)