This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author flox
Recipients flox
Date 2013-04-24.07:46:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1366789582.23.0.0218552351895.issue17825@psf.upfronthosting.co.za>
In-reply-to
Content
I noticed a difference between computation of column offset for SyntaxError and IndentationError (a subclass of SyntaxError).
It is slightly confusing.


def report(exc):
    print('lineno %s, offset %s' % (exc.lineno, exc.offset))
    raise

try:
    exec('except IOError:')
except Exception as e:
    report(e)

try:
    exec('    open(filepath)')
except Exception as e:
    report(e)


** OUTPUT **
lineno 1, offset 6
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "<stdin>", line 2, in <module>
  File "<string>", line 1
    except IOError:
         ^
SyntaxError: invalid syntax

lineno 1, offset 4
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "<stdin>", line 2, in <module>
  File "<string>", line 1
    open(filepath)
    ^
IndentationError: unexpected indent


** Analysis **

Case (1): offset is 6, and caret is below column 5 for SyntaxError
Case (2): offset is 4, and caret is below column 4 for IndentationError
History
Date User Action Args
2013-04-24 07:46:22floxsetrecipients: + flox
2013-04-24 07:46:22floxsetmessageid: <1366789582.23.0.0218552351895.issue17825@psf.upfronthosting.co.za>
2013-04-24 07:46:22floxlinkissue17825 messages
2013-04-24 07:46:21floxcreate