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

Notes added to "SyntaxError" (and subclasses) are not displayed #109179

Closed
Delgan opened this issue Sep 9, 2023 · 2 comments · Fixed by #109197
Closed

Notes added to "SyntaxError" (and subclasses) are not displayed #109179

Delgan opened this issue Sep 9, 2023 · 2 comments · Fixed by #109197
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 new features, bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@Delgan
Copy link
Contributor

Delgan commented Sep 9, 2023

Bug report

Bug description:

Hi.

I noticed that using add_note() with an error of type SyntaxError (or its derived such as IndentationError and TabError) produces a traceback without the expected notes.

Here is a minimal reproducible example:

try:
    exec("a = 7 *")
except SyntaxError as e:
    e.add_note("Note")
    raise

Or alternatively:

e = SyntaxError("invalid syntax", ("<string>", 1, 8, "a = 7 *\n", 1, 8))
e.add_note("Note")
raise e

The output of these examples is:

Traceback (most recent call last):
  File "/home/delgan/test.py", line 2, in <module>
    exec("a = 7 *")
  File "<string>", line 1
    a = 7 *
           ^
SyntaxError: invalid syntax

The expected "Note" is missing.

Since neither PEP 678 nor the documentation mention that SyntaxError is not fully compatible with notes, I assume that this is probably a bug.

CPython versions tested on:

3.11, 3.12

Operating systems tested on:

Linux

Linked PRs

@Delgan Delgan added the type-bug An unexpected behavior, bug, or error label Sep 9, 2023
@terryjreedy terryjreedy added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Sep 9, 2023
@terryjreedy
Copy link
Member

Test code above works with IndexError, for instance. The .__notes__ attribute is added but not used.
@iritkatriel You added this and its doc.

@iritkatriel iritkatriel added 3.11 only security fixes 3.12 bugs and security fixes 3.13 new features, bugs and security fixes labels Sep 9, 2023
iritkatriel added a commit to iritkatriel/cpython that referenced this issue Sep 9, 2023
@iritkatriel
Copy link
Member

Thanks, this is a bug. SyntaxError is handled differently and it drops the notes. Fixed in #109197.

iritkatriel added a commit to iritkatriel/cpython that referenced this issue Sep 11, 2023
iritkatriel added a commit to iritkatriel/cpython that referenced this issue Sep 11, 2023
iritkatriel added a commit to iritkatriel/cpython that referenced this issue Sep 11, 2023
kumaraditya303 pushed a commit that referenced this issue Sep 12, 2023
…109197) (#109283)

gh-109179: Fix traceback display for SyntaxErrors with notes (#109197)

(cherry picked from commit ecd21a6)
Yhg1s pushed a commit that referenced this issue Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 new features, bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants