Message284558
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. |
|
Date |
User |
Action |
Args |
2017-01-03 13:12:57 | vstinner | set | recipients:
+ vstinner, eric.smith, serhiy.storchaka, Jim Fasarakis-Hilliard |
2017-01-03 13:12:57 | vstinner | set | messageid: <1483449177.74.0.278410578726.issue29104@psf.upfronthosting.co.za> |
2017-01-03 13:12:57 | vstinner | link | issue29104 messages |
2017-01-03 13:12:57 | vstinner | create | |
|