Member-only story

Static Duck Typing With Python’s Protocols

The Turing Taco Tales
7 min readDec 4, 2023

--

Explore the power of Protocols in Python 3.8 for dynamic and robust type checking, as detailed in PEP 544. Learn how Protocols enhance Python’s type system by focusing on behavior-based interfaces and stay tuned for our deep dive into Protocol inheritance rules in our next article.

© 2023 The Turing Taco Tales / Oscar Mauricio Forero Carrillo

Originally published at The Turing Taco Tales on December 4, 2023.

Duck Typing in Cyberspace: Python’s Dynamic Typing Paradigm

In our ongoing series at The Turing Taco Tales, we’ve been unraveling the intricacies of Python’s type system. Previously, we’ve delved into the realm of type hints and type variables, unveiling how these features enhance code readability and maintainability. Today, we embark on a new chapter: the advent of Protocols in Python 3.8.

To appreciate the significance of Protocols, we must first understand two contrasting typing paradigms in programming languages: nominal and structural. Nominal typing, predominant in languages like Java, relies on explicit declarations and their names. Two objects have the same type if their types have the same name, and a type is a subtype of another if there is an explicitly declared either through the implements or extend keywords.

In contrast, structural typing, also popularly known as duck typing in dynamically typed languages, is…

--

--

No responses yet