Added specification for order of escape sequence processing.
This commit is contained in:
parent
088fee8cb8
commit
c0c7101fa5
19
pep-0498.txt
19
pep-0498.txt
|
@ -208,6 +208,25 @@ Expressions cannot contain ':' or '!' outside of strings or parens,
|
||||||
brackets, or braces. The exception is that the '!=' operator is
|
brackets, or braces. The exception is that the '!=' operator is
|
||||||
special cased.
|
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
|
Code equivalence
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue