Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

YouTube

How You Can Benefit from Type Hints

EuroPython Conference via YouTube

Overview

Discover the benefits of type hints in Python through this informative conference talk from EuroPython 2015. Explore how PEP 484 introduces type hints for Python 3, enhancing code readability for both humans and tools. Learn practical examples of type hint usage, their value in public APIs, and how they can lead to better and safer outcomes. Gain insights into using simple class types and built-in collection types for public APIs, and understand the advantages of type hinting stubs for third-party libraries. Delve into topics such as informal type hints, function annotations, type checking, type inference, code completion, and documentation improvements. Examine the ElementTree API as a practical example, and explore the spectrum from simple to complex type hints. Understand the liberal vs. conservative approaches to type hinting, and learn how to implement type hints in your own code using Python 3 function annotations. Discover available type hints and leave inspired to try them in your Python projects.

Syllabus

Intro
What This Talk is About
Quick Poll
Type Hints Used to Be Informal • An example from the standard library
PEP 484: Type Hints . Based on function annotations, Python 3.5 - Explicit is better than implicit
The Main Benefit • Improved readability for both humans and tools • Documentation - More compact and easier to grasp than lengthy native
The Tools
The Example: ElementTree
Exceptions
Add Type Hints • Start with a few function annotations
Type Checking
Let's Annotate ElementTree's API - Most type hints are simple
Type Inference • Tools can infer types in some cases Follow assignments to variables Return types of local functions
Code Completion • Context-sensitive code completion
Docs with Type Hints • From the docstring using the Sphinx autodoc extension
Type Hints for Your Public APIs
From Simple to Complex
Liberal vs Conservative
Type Hints in Your Code • Type hints in Python 3 function annotations It's enough to pip install a library • Compatible with Python 3.5
Python Stubs
Available Type Hints
Try Type Hints!

Taught by

EuroPython Conference

Reviews

Start your review of How You Can Benefit from Type Hints

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.