Episode 88: Discussing Type Hints, Protocols, and Ducks in Python
The Real Python Podcast
Dec 03, 2021 1h 21m
There seem to be three kinds of Python developers: those unaware of type hints or have no opinion, ones that embrace them, and others who have an allergic reaction at the mention of them. Python is famously a dynamically typed language, but there are advantages to adding type hints to your code. This week on the show, we have Luciano Ramalho to discuss his recent talk titled, “Type hints, protocols, and good sense.”
Luciano was not a fan of type hints. He’s only recently come around to their potential with the introduction of protocols in PEP 544. Python has adopted a gradual type system that is optional at all levels. We discuss the advantages, pitfalls, and recent developments around type hinting in Python.
We also talk about the second edition of Luciano’s book Fluent Python. He researched type hints in-depth for the book, which led to his recent conference talks on the subject. He also shares his experience with adding opinionated asides to the book in a fun and unique way.
Course Spotlight: Python Type Checking
In this course, you’ll look at Python type checking. Traditionally, types have been handled by the Python interpreter in a flexible but implicit way. Recent versions of Python allow you to specify explicit type hints that can be used by different tools to help you develop your code more efficiently.
- 00:00:00 – Introduction
- 00:02:02 – Are you interested in creative uses for Python?
- 00:04:41 – Protocol: The keystone of type hints
- 00:08:14 – What is duck typing?
- 00:12:44 – Protocols declaring one method and emerging from a code base
- 00:17:04 – An example where type hint was too lax
- 00:21:20 – What if Python always had a strict type system?
- 00:33:23 – Sponsor: Cloudsmith
- 00:34:09 – Bias in companies using type hints, and projects that fail checking
- 00:40:27 – Background on personal use of type hints and added complexity
- 00:45:07 – Unsuitability of type hints for checking business rules
- 00:52:30 – Video Course Spotlight
- 00:53:46 – Fluent Python, 2nd edition
- 00:56:05 – Who is the intended developer for the book?
- 00:58:12 – Soapbox sections of the book
- 00:59:35 – What were things you were excited to update or add to the book?
- 01:05:46 – Metaprogramming portion of the book
- 01:08:17 – What are you excited about in the world of Python?
- 01:10:35 – What do you want to learn next?
- 01:18:41 – Shoutouts, plugs, and/or social connections
- 01:19:47 – Thanks and goodbye
- Fluent Python, 2nd Edition
- Protocol: The keystone of type hints - Luciano Ramalho | PyCon US 2021
- Type hints, protocols, and good sense: PyCon India 2021 - Speaker Deck
- Generate buzz with realtime FM audio synthesis - Łukasz Langa | PyCon US 2021
- Garoa Hacker Clube
- Processing.py - Tutorials
- PEP 544 – Protocols: Structural subtyping (static duck typing) | Python.org
- typeshed: Collection of library stubs for Python, with static types
- Python Type Checking (Guide) – Real Python
- Protocols and structural subtyping — Mypy documentation
- Dependent type - Wikipedia
- microsoft/pyright: Static type checker for Python
- Welcome to mypy documentation!
- PEP 487 – Simpler customisation of class creation | Python.org
- PEP 636 – Structural Pattern Matching: Tutorial | Python.org
- What’s New In Python 3.10 — Better error messages
- Flutter - Build apps for any screen
- Luciano Ramalho Twitter(@ramalhoorg)