diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2022-11-06 13:52:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-06 13:52:06 (GMT) |
commit | 99e2e60cb25bfcf77ba1386d331cfa85864e6a65 (patch) | |
tree | 9aec45b4196922f64b17f82a52761514347c8d25 /Doc/whatsnew | |
parent | a0bc75e2fdd53680cb147881bcb3754bd56aa2fa (diff) | |
download | cpython-99e2e60cb25bfcf77ba1386d331cfa85864e6a65.zip cpython-99e2e60cb25bfcf77ba1386d331cfa85864e6a65.tar.gz cpython-99e2e60cb25bfcf77ba1386d331cfa85864e6a65.tar.bz2 |
gh-99139: Improve NameError error suggestion for instances (#99140)
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r-- | Doc/whatsnew/3.12.rst | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index b6daa6d..fb28d67 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -75,6 +75,27 @@ Important deprecations, removals or restrictions: Improved Error Messages ======================= +* Improve the error suggestion for :exc:`NameError` exceptions for instances. + 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`. + + >>> 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`. |