[Python-checkins] peps: Added specification for order of escape sequence processing.

eric.smith python-checkins at python.org
Fri Aug 28 20:26:54 CEST 2015


https://hg.python.org/peps/rev/c008f6cc1411
changeset:   6003:c008f6cc1411
user:        Eric V. Smith <eric at trueblade.com>
date:        Fri Aug 28 14:26:58 2015 -0400
summary:
  Added specification for order of escape sequence processing.

files:
  pep-0498.txt |  19 +++++++++++++++++++
  1 files changed, 19 insertions(+), 0 deletions(-)


diff --git a/pep-0498.txt b/pep-0498.txt
--- a/pep-0498.txt
+++ b/pep-0498.txt
@@ -208,6 +208,25 @@
 brackets, or braces. The exception is that the '!=' operator is
 special cased.
 
+Escape sequences
+----------------
+
+Scanning an f-string for expressions happens after escape sequences
+are decode. Because hex(ord('{')) == 0x7b, that means that the
+f-string f'\u007b4*10}' is decoded to f'{4*10}', which evaluates as
+the integer 40::
+
+  >>> f'\u007b4*10}'
+  '40'
+  >>> f'\x7b4*10}'
+  '40'
+  >>> f'\x7b4*10\N{RIGHT CURLY BRACKET}'
+  '40'
+
+These examples aren't generally useful, they're just to show that
+escape sequences are processed before f-strings are parsed for
+expressions.
+
 Code equivalence
 ----------------
 

-- 
Repository URL: https://hg.python.org/peps


More information about the Python-checkins mailing list