Uncovering the magic of implementing a new Python syntax feature

Track:
Python Core, Internals, Extensions
Type:
Talk
Level:
intermediate
Duration:
30 minutes

Abstract

From Python’s new type parameter syntax and exception groups to structural pattern matching and assignment expressions, these are only a few of Python’s multitude of syntax features that all of us can use to make our lives easier.

But have you ever thought about what it takes to implement these features? How does your source code get transformed, so that Python knows what to do in order to produce the output that you expect (or not)? The tokenizer, the parser, the bytecode compiler and the interpreter are all pieces to the puzzle of how Python does its magic.

In this talk, we’ll look behind Python’s curtains and try to understand together how the CPython implementation takes in your source code, generates a token stream, creates from it an Abstract Syntax Tree, emits bytecode and finally interprets that bytecode to run your programs. And who knows? Maybe you’ll get to hear about some new and shiny syntax features as well!