[New-bugs-announce] [issue26713] Change f-literal grammar so that escaping isn’t possible or necessary

flying sheep report at bugs.python.org
Fri Apr 8 10:53:50 EDT 2016


New submission from flying sheep:

code inside of the braces of an f-literal should have the exact same lexing rules than outside *except* for an otherwise unparsable !, :, or } signifying the end of the replacement field

1. every other language with template literals has it that way
2. it makes sense that the content of the f-literal is a “hole” in which normal code goes until a !, : or } signifies its end
3. escaping code that will be evaluated reeks of “eval” even though it isn’t

as it is now, it’s very confusing as the contents are neither code nor string content.

that might be one reason why many people get it wrong and think it can be stored unevaluatedly and thus provides a security risk (which is obv. wrong)

the whole section after “A consequence of sharing the same syntax as regular string literals is…” has to be removed and made unnecessary by allowing everything otherwise legal inside.

e.g. f'spam{(lambda: 1)():<4}' would be legal and be exactly the same as '{:<4}'.format((lambda: 1)())

----------
messages: 263026
nosy: flying sheep
priority: normal
severity: normal
status: open
title: Change f-literal grammar so that escaping isn’t possible or necessary

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26713>
_______________________________________


More information about the New-bugs-announce mailing list