Python 3.11 Frame Object Changes

Are you ready for some exciting news? The latest version of our beloved language has arrived, and it brings with it some major updates to the frame object.

To kick things off: what’s a frame object anyway? Well, in simple terms, it’s like a snapshot of your code at a specific point in time. It contains all sorts of juicy details about variables, functions, and other goodies that can help you debug and optimize your programs.

But enough with the boring stuff! Let’s begin exploring with some of the coolest changes to frame objects in Python 3.11:

1️ Say goodbye to #include ! That’s right, you no longer need to include this header file to access frame functions and types directly from your code. Instead, they’re now available with just a simple #include .

2️ The PyFrameObject structure members have been removed from the public C API! That means you can say goodbye to all those ***** fields that were once part of frame objects, like f_back and f_locals. Instead, they’re now managed by the virtual machine itself which is a fancy way of saying “we did some optimization stuff behind the scenes”.

3️ Debuggers can now call PyFrame_GetLocals() instead of accessing f_locals directly! This is great news for anyone who’s ever struggled with debugging their code, as it eliminates a common source of errors and confusion. Plus, you no longer need to worry about calling functions like PyFrame_FastToLocalsWithError or PyFrame_LocalsToFast the virtual machine takes care of all that for you!

4️ The _frozen module now has a new is_package field, which indicates whether it’s a package. This replaces the negative value in the size field that was previously used to indicate this same thing but with a much more intuitive and readable approach!

5️ The PyCodeObject no longer has fields like co_code, co_varnames, co_cellvars, or co_freevars. Instead, you can create code objects using the compiler, then get modified versions with the replace method which is a much more efficient and streamlined approach!

11! Whether you’re a seasoned pro or just starting out, these updates are sure to make your coding experience faster, easier, and more enjoyable than ever before.

SICORPS