Talks: PEP 695, or how typing syntax led to a scoping rabbit hole

Friday - May 17th, 2024 1:45 p.m.-2:30 p.m. in Room 301-305

Presented by:

Description

One of the biggest changes in Python 3.12 was PEP 695, which introduced new syntax for generic classes, functions, and type aliases. This was a complicated change, involving a new soft keyword, many new grammar rules, and a few new bytecode instructions. Unexpectedly, the one aspect that led to the most complexity was the way the new syntax interacts with class scopes. Class scopes in Python are weird.

This talk will outline what motivated PEP 695, how the implementation works, and how it may be improved in the future. It will describe how the new syntax provides a more intuitive way to express generics, and also explore in depth how class scopes work and how we designed the new syntax to work in harmony with existing scoping rules. Finally, we'll talk about ways the syntax may change in the future.