2025-07-25 –, Auditorium
Decorators are a powerful way to extend functions, but their flexibility can lead to ambiguity and runtime errors. By using type annotations, we can clarify their behavior and leverage mypy and pyright to catch mistakes early.
This talk explores typing.ParamSpec, TypeVarTuple, Protocol, Concatenate, and other tools to create type-safe decorators that preserve function signatures. You'll learn best practices to improve readability, reduce debugging time, and write more maintainable Python code.
Decorators are a powerful and elegant way to modify or extend the behavior of functions in Python. However, their flexibility often comes at the cost of clarity—what arguments should be passed, which functions can they wrap, and how do they affect return types? These uncertainties can lead to unexpected bugs and runtime errors.
By incorporating type annotations, we can eliminate ambiguity and leverage static type checkers like mypy and pyright to catch mistakes before they become problems. Well-typed decorators not only enhance code readability but also provide early warnings about incorrect usage, reducing debugging time and improving maintainability.
In this talk, we will explore practical techniques for defining type-safe decorators using typing.ParamSpec, TypeVarTuple, Protocol, Concatenate, and Type Parameter Syntax. You'll learn how to build decorators that preserve function signatures, work seamlessly with type checkers, and integrate smoothly into robust Python projects. Whether you're new to type hints or looking to refine your decorator skills, this session will equip you with the tools and best practices to write cleaner, safer, and more maintainable Python code.
Intermediate
What are the main topics of your talk?:Python’s Typing Tools for Decorators
Ansab is a seasoned data scientist and AI engineer with extensive experience in building robust AI models and solving complex data challenges in his Software Engineering career. Passionate about technology and data-driven innovation, has worked on diverse projects that emphasize quality, scalability, and adaptability in software systems. Through his work, he aims to empower teams to develop smarter, more inclusive data-driven solutions.