Better Programming

Advice for programmers.

Follow publication

Member-only story

Python’s Type Hinting: Friend, Foe, or Just a Headache?

Marcin Kozak
Better Programming
Published in
10 min readSep 30, 2022

--

A big light question mark down the tunnel.
Python: Does hinting using type hints truly help? Photo by Emily Morter on Unsplash

All Pythonistas know that for a couple of years, Python’s type hinting has been rapidly gaining popularity. It started back in Python 3.5, and ever since, this functionality has been getting more types and functions, and— in Python 3.10 — even a new operator, |. Fortunately or not, this operator has a similar meaning to the same operator used for sets.

I’ve heard varying opinions on type hinting, ranging from rage and hatred to love and devotion. Most authors who write about type hints in Python consider them helpful, something that increases code readability, particularly in the case of a large code base. When doing so, however, they usually show very simple examples of type hints.

Although type hints enable one to use static type checkers, we will not discuss this topic in this article. I will just admit that such static checking can be a helpful tool indeed. Here, we will discuss a little more controversial topic, that is, whether type hints are helpful at all. Some people take this for granted, but I don’t. I want to see the proof. Like with almost everything, too much of a good thing can be bad…

--

--

Marcin Kozak
Marcin Kozak

Written by Marcin Kozak

A full professor, interdisciplinary researcher, data scientist, statistician, Python, R and Go developer, open-source contributor — and a devoted writer

Write a response