STINNER Victor added the comment:
The PEP 498 should be updated to define the expected behaviour of f'\{5}':
https://www.python.org/dev/peps/pep-0498/#escape-sequences
+ self.assertEqual(f'\{6*7}', '\\42')
+ self.assertEqual(f'\\{6*7}', '\\42')
+ self.assertEqual(fr'\{6*7}', '\\42')
+
+ AMPERSAND = 123
+ self.assertEqual(f'\N{AMPERSAND}', '&')
+ self.assertEqual(f'\\N{AMPERSAND}', '\\N123')
+ self.assertEqual(fr'\N{AMPERSAND}', '\\N123')
+ self.assertEqual(f'\\\N{AMPERSAND}', '\\&')
I'm not sure that I like this behaviour.
f'\\N{AMPERSAND}': reading a local variable looks like a typo or a security
vulnerability, rather than a nice feature.
IMHO if you want an anti-slash (\) in the output string, it *must* be written
"\\" since we *do* interpret other escape sequences:
* f'\n' returns '\n', the newline character U+000A
* f'\N{Snowman}' returns the nice snowman character U+2603 (☃)
* etc.
What is the issue with having to write "\\{10}" to get "\\10" string? It's less
error prone.
----------
nosy: +haypo
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue29104>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com