Skip to content

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

Description

@Delgan

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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Sep 9, 2023
  2. terryjreedy commented on Sep 9, 2023

    @terryjreedy
    Member

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

  3. added
    3.11only security fixes
    3.12only security fixes
    3.13only security fixes
    on Sep 9, 2023
  4. added a commit that references this issue on Sep 9, 2023
  5. iritkatriel commented on Sep 9, 2023

    @iritkatriel
    Member

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

  6. added 4 commits that reference this issue on Sep 11, 2023
  7. added a commit that references this issue on Sep 12, 2023
  8. added a commit that references this issue on Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13only security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions