Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

YouTube

Protocols and Practices Enforcing in Python Through Bytecode and Inspection

EuroPython Conference via YouTube

Overview

Explore advanced techniques for enforcing protocols and best practices in Python through bytecode manipulation and code inspection in this 42-minute EuroPython Conference talk. Dive into the powerful introspection features of Python, including access to bytecode, to implement robust checks on third-party and future code. Learn how to verify and enforce constraints by examining the actual bytecode to be executed, going beyond traditional runtime checks, metaclasses, and monkeypatching. Discover practical examples of using these techniques to ensure proper resource management and prevent common anti-patterns, providing a more reliable alternative to static code analysis tools for custom checks and expectations in your Python projects.

Syllabus

Intro
Why? • Being more the Ubrary kind of developer tend to write a lot of independent pieces When you put those together to do the real job it's not always easy to comunicate their design and philosophy • Developers tend to do the best they can with what they have
Then comes documentation • To avoid misuses you try to cover examples for most reasonable use cases in documentation You quickly discover that your definition of reasonable is not as common as you thought
Protocols & Expectations • Protocols define how components interact with the rest of the world. Invest time in enforcing them and refuse violations • Developers have expectations out of your libraries your libraries should have expectations too
Protocols & Expectations • Protocols define how components interact with the rest of the world. Invest time in enforcing them and refuse violations.
Enforcing Protocols • Interfaces, Signatures. Types, Assertions are all ways to express a protocol. • They can provide expectations about joints between your code and users code . But they can do little about expectations on 'context where your library runs in
Enforcing Protocols Interfaces. Signatures. Types. Assertions are all ways to express a protocol • They can provide expectations about joints between your code and users code • But they can do little about expectations on context where your library runs in
The Context • Python is a Dynamic language with powerful inspection techniques.
The Context • Python is a Dynamic language with powerful inspection techniques • Inspection is often used for Debugging but it's a powerful tool to check expectations
The Context • Checking for anti-patterns is something static code analysis tools usually do But they are one more dependency and plece to integrate into build pipeline. They are usually pretty complex to adapt with custom checks if even possible. • They can check your code only
The Context • Checking for anti-patterns is something static code analysis tools usually do • But they are one more dependency and piece to integrate into build pipeline. • They are usually pretty complex to adapt with custom checks if even possible. They can check your code only
For Example? . I used code inspection to ensure no files are left behind clue to a failure in any method called when a resource is destroyed

Taught by

EuroPython Conference

Reviews

Start your review of Protocols and Practices Enforcing in Python Through Bytecode and Inspection

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.