[New-bugs-announce] [issue47129] Improve errors messages in f-string syntax errors

Maciej Górski report at bugs.python.org
Sat Mar 26 11:08:27 EDT 2022


New submission from Maciej Górski <macgors at gmail.com>:

When an empty expression is provided in curly brackets inside an f-string we get Syntax Error: "f-string: empty expression not allowed".


This is correct, however error with the same message is raised in the following cases: f"{!foo}", f"{!}", f"{:bar}", f"{=}", etc.
For example, should someone make an error and try to negate an expression with '!' instead of 'not' (i.e. f"{!True}"), they would get a confusing error, saying that the expression is empty, when it isn't. 

I propose we raise an error with the message: "f-string: optional specifier '%c' must follow a non-empty expression.

----------
components: Parser
messages: 416069
nosy: lys.nikolaou, macgors, pablogsal
priority: normal
severity: normal
status: open
title: Improve errors messages in f-string syntax errors

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue47129>
_______________________________________


More information about the New-bugs-announce mailing list