f"yeah!" - How we are supercharging f-strings in Python 3.12
07-19, 11:35–12:05 (Europe/Prague), PyCharm (Forum Hall)

Everybody loves f-strings in Python. But what if they could be even better? Thanks to PEP 701, Python 3.12 will ship with an improved version of f-strings that will once and for all fix the little remaining problems that f-strings have had, while also supercharging them with new cool powers. In this talk, you will discover the dark little secrets of how f-strings were being processed before Python 3.12 and the many things that didn't work and you didn't know about. You will learn how we changed thousands of lines of manually written C code without anybody noticing, how we changed the oldest part of CPython so quotes behave like parentheses, and how we taught the PEG parser to understand f-strings. Plus, you'll gain an understanding of how these new and improved capabilities will provide several advantages for both end-users and library developers, while also reducing the maintenance cost of the CPython implementation.

In this talk, we will cover one of the primary syntactic changes of Python 3.12: PEP 701 – Syntactic formalisation of f-strings. Here is the structure of the talk: - How f-strings were originally introduced - Problems with f-strings * Backslashes cannot be used within the expression part of f-strings * It is impossible to use the quote character delimiting the f-string within the expression portion * Comments are forbidden, even in multi-line f-strings * Arbitrary nesting of expressions without expansion of escape sequences is impossible * There is no referential transparency - How f-strings are currently parsed: The two-pass process - How PEP 701 formalises a grammar for f-strings - How we changed the tokeniser and parser to understand f-strings - Syntactic and semantic consequences of the new grammar - Implementation challenges Attendees will not only learn the (normally unknown) problems that f-strings previously had, but also will learn through the journey of how the PEP was implemented several techniques and approaches to changing big codebases such as CPython in an efficient way, while minimising user impact. Attendees will also learn how changes to the CPython grammar that also require lexer changes are implemented, which is quite a unique situation, as most changes to the Python Grammar do not require lexer changes. No matter whether someone is new to Python or an advanced developer that enjoys hacking with the interpreter, there is something in this talk for them.

Expected audience expertise


Pablo Galindo Salgado programs the programming program that other programmers use to program programs. He also works in the Python Infrastructure team at the Software Infrastructure department at Bloomberg L.P. Pablo is a CPython core developer and a Theoretical Physicist specializing in general relativity and black hole physics. He is currently serving on the Python Steering Council and he is the release manager for Python 3.10 and 3.11. He has also a cat but he does not code.

This speaker also appears in:

Marta is software engineer at VirusTotal, an online threat analysis platform which is part of Google Cloud Security. She has more than 6 years of experience in the cybersecurity industry and she coded in Python for almost 10 years.

This speaker also appears in: