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.

Topics:

  • 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

Show Links:

Level up your Python skills with our expert-led courses:

Support the podcast & join our community of Pythonistas