Contribute Media
A thank you to everyone who makes this possible: Read More

Protocols and Practices enforcing in Python through bytecode and inspection


Python is an interpreted development language with powerful introspection features, up to allow accesso to the byte code itself to see what the virtual machine is going to do. Reaching down to byte code or low level inspection is usually a very uncommon need and it's usually only involved in debugging or understanding the interpreter internals, but it can be a powerful tool to check that third parties code that (or the code we will write ourselves in the future) sticks to some protocols or best practices that are supposed to be in place.

Most of the needs for this checks are usually performed at execution time or through techniques like metaclasses and monkeypatching of third parties code, but in some cases it would be possible to inadvertently skip those checks or work them around, while verifying the resulting byte code allows us to check what's really going to be executed and enforce the required constraints.


Improve this page