Search⌘ K
AI Features

Introduction to Typing Module

Explore the Python typing module introduced in Python 3.5 to add type hints to functions. Understand how to indicate expected argument and return types including built-in and user-defined classes, while recognizing that these hints are non-binding. Learn to create type aliases and improve code readability and maintainability with practical examples.

Python 3.5 added an interesting new library called typing. This adds type hinting to Python.

Type hinting is kind of declaring our function’s arguments to have a certain type. However the type hinting is not binding. It’s just a hint, so there’s nothing preventing the programmer from passing something they shouldn’t. This is Python after all. We can read the type hinting specification in ...