PEP 701: Mention about code generators (#2940)

This commit is contained in:
Batuhan Taskaya 2022-12-26 19:44:31 +03:00 committed by GitHub
parent d547ef7ef4
commit d1cfb37937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -403,6 +403,13 @@ Here are some of the arguments in favour:
def py2c(source):
return f"{source.removesuffix(".py")}.c"
* Code generators (like `ast.unparse <https://docs.python.org/3/library/ast.html#ast.unparse>`_ from standard library) in their
current form rely on complicated algorithms to ensure expressions within an f-string are properly suited for the context in
which they are being used. These non-trivial algorithms come with challanges such as finding an unused quote type (by tracking
the outer quotes), and generating string representations which would not include backslashes if possible. Allowing quote reuse
and backslashes would simplify the code generators which deals with f-strings considerably, as the regular Python expression logic
can be used inside and outside of f-strings without any special treatment.
* Limiting quote reuse will considerably increase the complexity of the implementation of the proposed changes. This is because
it will force the parser to have the context that is parsing an expression part of an f-string with a given quote in order
to know if it needs to reject an expression that reuses the quote. Carrying this context around is not trivial in parsers that