From 24e79db83c596b3029109d0be8dc4efd488d1a11 Mon Sep 17 00:00:00 2001 From: Ammar Askar Date: Fri, 2 Apr 2021 12:56:25 -0400 Subject: [PATCH 1/2] bpo-43705: Document that SyntaxError's offsets are 1-indexed --- Doc/library/exceptions.rst | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst index 40ccde72d07cc3..fe387977ea47ef 100644 --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -402,9 +402,25 @@ The following exceptions are the exceptions that are usually raised. or :func:`eval`, or when reading the initial script or standard input (also interactively). - Instances of this class have attributes :attr:`filename`, :attr:`lineno`, - :attr:`offset` and :attr:`text` for easier access to the details. :func:`str` - of the exception instance returns only the message. + The :func:`str` of the exception instance returns only the error message. + + .. attribute:: filename + + The name of the file the syntax error occurred in. + + .. attribute:: lineno + + Which line number in the file the error occurred in. Note that this is + 1-indexed, the first line in the file would have a ``lineno`` of 1. + + .. attribute:: offset + + The column in the line where the error occurred. Note that this is + 1-indexed, the first character in the line has an ``offset`` of 1. + + .. attribute:: text + + The source code text involved in the error. .. exception:: IndentationError From abd19add35ec293d94c194b4ab5c14fd39a08522 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 2 Apr 2021 14:11:36 -0700 Subject: [PATCH 2/2] Tighten wording a bit --- Doc/library/exceptions.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst index fe387977ea47ef..4dea6701a6bfd0 100644 --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -410,13 +410,13 @@ The following exceptions are the exceptions that are usually raised. .. attribute:: lineno - Which line number in the file the error occurred in. Note that this is - 1-indexed, the first line in the file would have a ``lineno`` of 1. + Which line number in the file the error occurred in. This is + 1-indexed: the first line in the file has a ``lineno`` of 1. .. attribute:: offset - The column in the line where the error occurred. Note that this is - 1-indexed, the first character in the line has an ``offset`` of 1. + The column in the line where the error occurred. This is + 1-indexed: the first character in the line has an ``offset`` of 1. .. attribute:: text