Thanks @erictraut for the message! I am very excited to know that you are adding PEP 701 support in pyright
! Thanks a lot for the great work 
Let me answer the points that you raise.
“How to produce these tokens” section. Step 3 doesn’t say anything special about what happens after a :
character is encountered. It says that the tokenizer should go back to step 2 after emitting a :
token and popping the current tokenizer mode from the stack. However, when in “format specifier” mode (i.e. after the :
is encountered), I think the rules for step 2 need to change so double braces ({{
or }}
) are no longer assumed to be part of an FSTRING_MIDDLE
token.
I think we may want to be a bit more explicit here, but the section was intended to be indicative and not prescriptive as different tokenizers would require different ways to approach the problem. You have a good point though because there is ambiguity over how the format specifier should be tokenized in general so we should describe that better. I will try to make a PR after beta freeze as we are currently fully immersed in the Python tokenizer changes.
You are right here but note this is not new as this is something we just preserved from the previous implementation:
ython 3.11.1 (main, Dec 15 2022, 18:32:52) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> f"{'':{{1}.pop()}}"
' '
[quote="Eric Traut, post:120, topic:22046, username:erictraut"]
Another small topic that isn’t mentioned in the PEP has to do with nested format specifiers. It appears that the implementation supports two levels of nesting but not three.
`f"{'':*^{1:{1}}}"` works
`f"{'':*^{1:{1:{1}}}}"` produces a syntax error (f-string: expressions nested too deeply)
[/quote]
This is also something we preserved from the previous implementation:
Python 3.11.1 (main, Dec 15 2022, 18:32:52) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> f"{'':*^{1:{1:{1}}}}"
File "<stdin>", line 1
f"{'':*^{1:{1:{1}}}}"
^
SyntaxError: f-string: expressions nested too deeply
For both of these things we just preserved existing behavior, while for the nesting of f-strings we had to dictate it because now arbitrary nesting is possible while before it was not.
Would it make sense for the PEP to mention a separate lower bound for format specifier nesting?
I think this is something that makes sense, just so is more clear what the default prescription/recommendation is.