-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Closed
Labels
3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixesstdlibPython modules in the Lib dirPython modules in the Lib dirtopic-importlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
If you call importlib.reload()
with a str
, there's a huge amount of unnecessary detail in the traceback that makes it look like there's an internal error in the function itself:
>>> import importlib
>>> import typing
>>> importlib.reload("typing")
Traceback (most recent call last):
File "/Users/alexw/.pyenv/versions/3.13.0/lib/python3.13/importlib/__init__.py", line 101, in reload
name = module.__spec__.name
^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute '__spec__'. Did you mean: '__doc__'?
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/alexw/.pyenv/versions/3.13.0/lib/python3.13/importlib/__init__.py", line 104, in reload
name = module.__name__
^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute '__name__'. Did you mean: '__ne__'?
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
importlib.reload("typing")
~~~~~~~~~~~~~~~~^^^^^^^^^^
File "/Users/alexw/.pyenv/versions/3.13.0/lib/python3.13/importlib/__init__.py", line 106, in reload
raise TypeError("reload() argument must be a module")
TypeError: reload() argument must be a module
We should probably suppress the exception context here.
CPython versions tested on:
3.12, 3.13, CPython main branch
Operating systems tested on:
macOS
Linked PRs
- gh-125519: Improve traceback if
importlib.reload()
is called with a non-module object #125520 - [3.13] gh-125519: Improve traceback if
importlib.reload()
is called with a non-module object (GH-125520) #125768 - [3.12] gh-125519: Improve traceback if
importlib.reload()
is called with a non-module object (GH-125520) #125769
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixesstdlibPython modules in the Lib dirPython modules in the Lib dirtopic-importlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error