The Real Python Podcast

Discussing Type Hints, Protocols, and Ducks in Python


Listen Later

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:

    • 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
    • Ramalho.org/wiki
    • Luciano Ramalho Twitter(@ramalhoorg)
    • Level up your Python skills with our expert-led courses:

      • Using Pygame to Build an Asteroids Game in Python
      • Records and Sets: Selecting the Ideal Data Structure
      • Python Type Checking
      • Support the podcast & join our community of Pythonistas

        ...more
        View all episodesView all episodes
        Download on the App Store

        The Real Python PodcastBy Real Python

        • 4.7
        • 4.7
        • 4.7
        • 4.7
        • 4.7

        4.7

        136 ratings


        More shows like The Real Python Podcast

        View all
        Software Engineering Radio - the podcast for professional software developers by se-radio@computer.org

        Software Engineering Radio - the podcast for professional software developers

        272 Listeners

        The Changelog: Software Development, Open Source by Changelog Media

        The Changelog: Software Development, Open Source

        283 Listeners

        Thoughtworks Technology Podcast by Thoughtworks

        Thoughtworks Technology Podcast

        41 Listeners

        Talk Python To Me by Michael Kennedy

        Talk Python To Me

        592 Listeners

        Software Engineering Daily by Software Engineering Daily

        Software Engineering Daily

        624 Listeners

        Soft Skills Engineering by Jamison Dance and Dave Smith

        Soft Skills Engineering

        269 Listeners

        Super Data Science: ML & AI Podcast with Jon Krohn by Jon Krohn

        Super Data Science: ML & AI Podcast with Jon Krohn

        298 Listeners

        Python Bytes by Michael Kennedy and Brian Okken

        Python Bytes

        213 Listeners

        Data Engineering Podcast by Tobias Macey

        Data Engineering Podcast

        142 Listeners

        Syntax - Tasty Web Development Treats by Wes Bos & Scott Tolinski - Full Stack JavaScript Web Developers

        Syntax - Tasty Web Development Treats

        982 Listeners

        DataFramed by DataCamp

        DataFramed

        266 Listeners

        Kubernetes Podcast from Google by Abdel Sghiouar, Kaslin Fields

        Kubernetes Podcast from Google

        181 Listeners

        Practical AI by Practical AI LLC

        Practical AI

        189 Listeners

        The Stack Overflow Podcast by The Stack Overflow Podcast

        The Stack Overflow Podcast

        64 Listeners

        The Pragmatic Engineer by Gergely Orosz

        The Pragmatic Engineer

        52 Listeners