Added specification for order of escape sequence processing.

This commit is contained in:
Eric V. Smith 2015-08-28 14:26:58 -04:00
parent 088fee8cb8
commit c0c7101fa5
1 changed files with 19 additions and 0 deletions

View File

@ -208,6 +208,25 @@ Expressions cannot contain ':' or '!' outside of strings or parens,
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
----------------