Skip to content

bpo-44322: Document more SyntaxError details. #26562

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

Merged
merged 2 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
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: 9 additions & 2 deletions Doc/library/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -409,14 +409,16 @@ The following exceptions are the exceptions that are usually raised.

.. versionadded:: 3.5

.. exception:: SyntaxError
.. exception:: SyntaxError(message, details)

Raised when the parser encounters a syntax error. This may occur in an
:keyword:`import` statement, in a call to the built-in functions :func:`exec`
:keyword:`import` statement, in a call to the built-in functions
:func:`compile`, :func:`exec`,
or :func:`eval`, or when reading the initial script or standard input
(also interactively).

The :func:`str` of the exception instance returns only the error message.
Details is a tuple whose members are also available as separate attributes.

.. attribute:: filename

Expand Down Expand Up @@ -446,6 +448,11 @@ The following exceptions are the exceptions that are usually raised.
The column in the end line where the error occurred finishes. This is
1-indexed: the first character in the line has an ``offset`` of 1.

For errors in f-string fields, the message is prefixed by "f-string: "
and the offsets are offsets in a text constructed from the replacement
expression. For example, compiling f'Bad {a b} field' results in this
args attribute: ('f-string: ...', ('', 1, 2, '(a b)\n', 1, 5)).

.. versionchanged:: 3.10
Added the :attr:`end_lineno` and :attr:`end_offset` attributes.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Document that SyntaxError args have a details tuple and that details are
adjusted for errors in f-string field replacement expressions.