PLAY PODCASTS
Discussing Type Hints, Protocols, and Ducks in Python
Episode 88

Discussing Type Hints, Protocols, and Ducks in Python

The Real Python Podcast · Real Python

December 3, 20211h 21m

Audio is streamed directly from the publisher (dts.podtrac.com) as published in their RSS feed. Play Podcasts does not host this file. Rights-holders can request removal through the copyright & takedown page.

Show Notes

<p>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, &ldquo;Type hints, protocols, and good sense.&rdquo;</p> <p>Luciano was not a fan of type hints. He&rsquo;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.</p> <p>We also talk about the second edition of Luciano&rsquo;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.</p> <div class="alert alert-primary" role="alert"> <p><strong>Course Spotlight:</strong> <a href="https://realpython.com/courses/python-type-checking/">Python Type Checking</a> </p> <p>In this course, you&rsquo;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.</p> </div> <p>Topics:</p> <ul> <li>00:00:00 &ndash; Introduction</li> <li>00:02:02 &ndash; Are you interested in creative uses for Python?</li> <li>00:04:41 &ndash; Protocol: The keystone of type hints</li> <li>00:08:14 &ndash; What is duck typing?</li> <li>00:12:44 &ndash; Protocols declaring one method and emerging from a code base</li> <li>00:17:04 &ndash; An example where type hint was too lax</li> <li>00:21:20 &ndash; What if Python always had a strict type system?</li> <li>00:33:23 &ndash; Sponsor: Cloudsmith</li> <li>00:34:09 &ndash; Bias in companies using type hints, and projects that fail checking</li> <li>00:40:27 &ndash; Background on personal use of type hints and added complexity</li> <li>00:45:07 &ndash; Unsuitability of type hints for checking business rules</li> <li>00:52:30 &ndash; Video Course Spotlight</li> <li>00:53:46 &ndash; Fluent Python, 2nd edition</li> <li>00:56:05 &ndash; Who is the intended developer for the book?</li> <li>00:58:12 &ndash; Soapbox sections of the book</li> <li>00:59:35 &ndash; What were things you were excited to update or add to the book?</li> <li>01:05:46 &ndash; Metaprogramming portion of the book</li> <li>01:08:17 &ndash; What are you excited about in the world of Python?</li> <li>01:10:35 &ndash; What do you want to learn next?</li> <li>01:18:41 &ndash; Shoutouts, plugs, and/or social connections</li> <li>01:19:47 &ndash; Thanks and goodbye</li> </ul> <p>Show Links:</p> <ul> <li><a href="https://www.oreilly.com/library/view/fluent-python-2nd/9781492056348/">Fluent Python, 2nd Edition</a></li> <li><a href="https://www.youtube.com/watch?v=kDDCKwP7QgQ">Protocol: The keystone of type hints - Luciano Ramalho | PyCon US 2021</a></li> <li><a href="https://speakerdeck.com/ramalho/type-hints-protocols-and-good-sense">Type hints, protocols, and good sense: PyCon India 2021 - Speaker Deck</a></li> <li><a href="https://www.youtube.com/watch?v=eKEjkB2bXK4&amp;list=PL2Uw4_HvXqvYk1Y5P8kryoyd83L_0Uk5K&amp;index=49&amp;t=2s">Generate buzz with realtime FM audio synthesis - Łukasz Langa | PyCon US 2021</a></li> <li><a href="https://garoa.net.br/wiki/P%C3%A1gina_principal">Garoa Hacker Clube</a></li> <li><a href="https://py.processing.org/tutorials/">Processing.py - Tutorials</a></li> <li><a href="https://www.python.org/dev/peps/pep-0544/">PEP 544 &ndash; Protocols: Structural subtyping (static duck typing) | Python.org</a></li> <li><a href="https://github.com/python/typeshed/">typeshed: Collection of library stubs for Python, with static types</a></li> <li><a href="https://realpython.com/python-type-checking/#duck-types-and-protocols">Python Type Checking (Guide) – Real Python</a></li> <li><a href="https://mypy.readthedocs.io/en/latest/protocols.html">Protocols and structural subtyping — Mypy documentation</a></li> <li><a href="https://en.wikipedia.org/wiki/Dependent_type">Dependent type - Wikipedia</a></li> <li><a href="https://github.com/Microsoft/pyright">microsoft/pyright: Static type checker for Python</a></li> <li><a href="https://mypy.readthedocs.io/en/stable/">Welcome to mypy documentation!</a></li> <li><a href="https://www.python.org/dev/peps/pep-0487/">PEP 487 &ndash; Simpler customisation of class creation | Python.org</a></li> <li><a href="https://www.python.org/dev/peps/pep-0636/">PEP 636 &ndash; Structural Pattern Matching: Tutorial | Python.org</a></li> <li><a href="https://docs.python.org/3/whatsnew/3.10.html#better-error-messages">What&rsquo;s New In Python 3.10 — Better error messages</a></li> <li><a href="https://flutter.dev/">Flutter - Build apps for any screen</a></li> <li><a href="https://ramalho.org/wiki/doku.php?id=start/">Ramalho.org/wiki</a></li> <li><a href="https://twitter.com/ramalhoorg">Luciano Ramalho Twitter(@ramalhoorg)</a></li> </ul> <p>Level up your Python skills with our expert-led courses:</p> <ul> <li><a href="https://realpython.com/courses/asteroids-game-python-pygame/">Using Pygame to Build an Asteroids Game in Python</a></li> <li><a href="https://realpython.com/courses/records-sets-ideal-data-structure/">Records and Sets: Selecting the Ideal Data Structure</a></li> <li><a href="https://realpython.com/courses/python-type-checking/">Python Type Checking</a></li> </ul> <p><a rel="payment" href="https://realpython.com/join">Support the podcast &amp; join our community of Pythonistas</a></p>