Bug report
Bug description:
When import fails to import a module, it raises an ImportError with the name attribute set to the module it failed to import.
When runpy.run_module fails to import a module, it raises an ImportError with the name attribute set to None.
This seems to be an accidental difference, or at least an undocumented one:
>>> try:
... import foobar
... except ImportError as e:
... print(f"{e=} {e.name=}")
...
e=ModuleNotFoundError("No module named 'foobar'") e.name='foobar'
>>> try:
... import runpy
... runpy.run_module("foobar")
... except ImportError as e:
... print(f"{e=} {e.name=}")
...
e=ImportError('No module named foobar') e.name=None
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs
Bug report
Bug description:
When
importfails to import a module, it raises anImportErrorwith thenameattribute set to the module it failed to import.When
runpy.run_modulefails to import a module, it raises anImportErrorwith thenameattribute set toNone.This seems to be an accidental difference, or at least an undocumented one:
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs
ImportError.nameon errors fromrunpy.run_module/run_path#149159