Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.12] GH-109190: Copyedit 3.12 What's New: Improved Error Messages (GH-109654) #109687

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Improved Error Messages

* Modules from the standard library are now potentially suggested as part of
the error messages displayed by the interpreter when a :exc:`NameError` is
raised to the top level. Contributed by Pablo Galindo in :gh:`98254`.
raised to the top level. (Contributed by Pablo Galindo in :gh:`98254`.)

>>> sys.version_info
Traceback (most recent call last):
Expand All @@ -110,25 +110,24 @@ Improved Error Messages
Now if a :exc:`NameError` is raised in a method and the instance has an
attribute that's exactly equal to the name in the exception, the suggestion
will include ``self.<NAME>`` instead of the closest match in the method
scope. Contributed by Pablo Galindo in :gh:`99139`.
scope. (Contributed by Pablo Galindo in :gh:`99139`.)

>>> class A:
... def __init__(self):
... self.blech = 1
...
... def foo(self):
... somethin = blech

...
>>> A().foo()
Traceback (most recent call last):
File "<stdin>", line 1
somethin = blech
^^^^^
NameError: name 'blech' is not defined. Did you mean: 'self.blech'?


* Improve the :exc:`SyntaxError` error message when the user types ``import x
from y`` instead of ``from y import x``. Contributed by Pablo Galindo in :gh:`98931`.
from y`` instead of ``from y import x``. (Contributed by Pablo Galindo in :gh:`98931`.)

>>> import a.y.z from b.y.z
Traceback (most recent call last):
Expand All @@ -139,7 +138,7 @@ Improved Error Messages

* :exc:`ImportError` exceptions raised from failed ``from <module> import
<name>`` statements now include suggestions for the value of ``<name>`` based on the
available names in ``<module>``. Contributed by Pablo Galindo in :gh:`91058`.
available names in ``<module>``. (Contributed by Pablo Galindo in :gh:`91058`.)

>>> from collections import chainmap
Traceback (most recent call last):
Expand Down
Loading