summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-06-06 19:09:34 -0700
committerGitHub <noreply@github.com>2021-06-06 22:09:34 -0400
commit2af690fdb26d0312de056b54ddb113d3c44dee8c (patch)
tree977c3d122c5f2a4d86a7c1a9e842118a10204cc2
parentb5cedd098043dc58ecf9c2f33774cd7646506a92 (diff)
downloadcpython-git-2af690fdb26d0312de056b54ddb113d3c44dee8c.tar.gz
bpo-44322: Document more SyntaxError details. (GH-26562)
1. SyntaxError args have a tuple of other attributes. 2. Attributes are adjusted for errors in f-string field expressions. 3. Compile() can raise SyntaxErrors. (cherry picked from commit 67dfa6f2a508c325715625fe442f2ce20270a8b3) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
-rw-r--r--Doc/library/exceptions.rst11
-rw-r--r--Misc/NEWS.d/next/Documentation/2021-06-06-14-12-00.bpo-44322.K0PHfE.rst2
2 files changed, 11 insertions, 2 deletions
diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst
index 173c1c285f..d5d81dfd9e 100644
--- a/Doc/library/exceptions.rst
+++ b/Doc/library/exceptions.rst
@@ -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
@@ -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.
diff --git a/Misc/NEWS.d/next/Documentation/2021-06-06-14-12-00.bpo-44322.K0PHfE.rst b/Misc/NEWS.d/next/Documentation/2021-06-06-14-12-00.bpo-44322.K0PHfE.rst
new file mode 100644
index 0000000000..48dd7e6d97
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2021-06-06-14-12-00.bpo-44322.K0PHfE.rst
@@ -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.