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 …
3
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 th…
4
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 librarie…
5
Protocols & Expectations • Protocols define how components interact with the rest of the world. Invest time in enforcing them and refuse violations.
6
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 lit…
7
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…
8
The Context • Python is a Dynamic language with powerful inspection techniques.
9
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
10
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 comple…
11
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 co…
12
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
Description:
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.
Protocols and Practices Enforcing in Python Through Bytecode and Inspection