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 terry.reedy
Recipients ammar2, docs@python, gvanrossum, terry.reedy
Date 2021-04-02.22:53:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1617404021.55.0.887836789183.issue43705@roundup.psfhosted.org>
In-reply-to
Content
Should we mention that the 4 attributes are also available as a 4-tuple that is the 2nd item of the args tuple, after the message?  Doing so will help when illustrating the following.

For syntax errors in f-string fields, the expanded doc is still incomplete/erroneous.  The text attribute is the replacement expression wrapped in parentheses (or with {} replaced by ()), with \n added; the column is the (1-based) offset within that constructed source.

>>> try:
	compile("f'Bad {a b} field'", '', 'exec')
except SyntaxError as e:
	print(e.args)

('f-string: invalid syntax', ('', 1, 4, '(a b)\n'))

This was brought to my attention a week or so ago because IDLE still thinks that 4 refers to the  'a' of 'Bad' and marks it is the error location.  I had to deduce the rule from examples.

Whether for this issue or a new one, I am thinking of something like the following.
---

For syntax error instances, the args attribute is (error-message, details-tuple).  The str returns only the error message.  For convenience, the four details are also available as separate attributes.

<new list as is>

For errors in f-string fields, the message is prefixed by "f-string:" and the offset is the offset in a text constructed from the replacement expression.  For example, compiling f'Bad {a b} field' results in the following args attribute: ('f-string: invalid syntax', ('', 1, 4, '(a b)\n')).

I think it okay to require the reader to match '{a b}' and '(a b)\n' to deduce the transformation rule.  Messages other than 'invalid syntax', like 'closing parenthesis ...' get the same prefix.  Anything Python specific can be labelled as such.
History
Date User Action Args
2021-04-02 22:53:41terry.reedysetrecipients: + terry.reedy, gvanrossum, docs@python, ammar2
2021-04-02 22:53:41terry.reedysetmessageid: <1617404021.55.0.887836789183.issue43705@roundup.psfhosted.org>
2021-04-02 22:53:41terry.reedylinkissue43705 messages
2021-04-02 22:53:41terry.reedycreate