4 ms·
It is explicit, in that one must use the f'' prefix. There are no syntax changes as u'', b'', and r'' already exist. Positionals make bugs more likely.
by mixmastamyk 11y ago
It is explicit, in that one must use the f'' prefix. There are no syntax changes as u'', b'', and r'' already exist. Positionals make bugs more likely.
- schmichael 11y agoIt is implicit in that the interpolated values are specified anywhere in scope, not inline as with every other formatting option. I consider specifying the values or variables alongside the formatting string a requirement to be considered explicit, but I can see how it's a matter of opinion.
- sametmax 11y ago@decorator def decorated Is doing: decorated = decorator(decorated) The switch is implicit too. It's syntaxic sugar to gain a pratical and elegant syntax for a common use case. It's not going to introduce vulnerability. It's going to make your code easier to write and read. It's going to make bug easier to spot in formating. It's going to make shell sessions easier.
- schmichael 11y agoThe manipulation (@dec) is still right next to the thing being manipulated (def dec). I'm not trying to be pedantic. It really does affect readability when syntactic sugar's affect spans an entire scope. Whether or not that effect on readability is greater or less than the gain by the syntactic sugar is always a matter of opinion. Obviously my opinion is out of line with Python's core devs.
- schmichael 11y agoIt is a syntax change as before f"" was a syntax error: >>> f"foo" File "<stdin>", line 1 f"foo" ^ SyntaxError: invalid syntax
- mixmastamyk 11y agoI suppose technically true, though similar to adding a function that didn't exist before. The syntax extension part of the feature (adding a letter to the grammar) is minuscule.
- schmichael 11y ago> ... though similar to adding a function that didn't exist before. This is not true and exactly the distinction I'm trying to make: Adding new packages, functions, objects, etc. can all be backported to older versions and alternative implementations. They also require no updates to ASTs, linters, syntax highlighters, static analysis tools etc. Adding new syntax is backward incompatible (unless it's added as a from __future__ import to new old releases) and requires changes to all tools that parse Python syntax (the interpreter, ASTs, linters, transpilers, etc).
- mixmastamyk 11y agoOk, true, though I would argue that it isn't entirely new syntax but rather a variation of an existing one. It is a shame that linters will have to add a letter to their grammar also, but I argue that the everyday usability and readability for millions will outweigh this drawback.