mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-98254: Include stdlib module names in error messages for NameErrors (#98255)
This commit is contained in:
parent
3a639bbeac
commit
bb56dead33
6 changed files with 101 additions and 31 deletions
|
@ -712,6 +712,13 @@ class TracebackException:
|
|||
suggestion = _compute_suggestion_error(exc_value, exc_traceback)
|
||||
if suggestion:
|
||||
self._str += f". Did you mean: '{suggestion}'?"
|
||||
if issubclass(exc_type, NameError):
|
||||
wrong_name = getattr(exc_value, "name", None)
|
||||
if wrong_name is not None and wrong_name in sys.stdlib_module_names:
|
||||
if suggestion:
|
||||
self._str += f" Or did you forget to import '{wrong_name}'"
|
||||
else:
|
||||
self._str += f". Did you forget to import '{wrong_name}'"
|
||||
if lookup_lines:
|
||||
self._load_lines()
|
||||
self.__suppress_context__ = \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue