PROGRAMMING

📝Python’s Type Annotations📝 — Why You Always Should Use It

Beauty and power of type annotations in Python or why I always use it

Mikhail Raevskiy
5 min readOct 30, 2020

--

Photo by author

Python is a dynamically typed language and allows us to operate fairly freely on variables of different types. However, when writing code, we somehow assume which types of variables will be used (this may be caused by a limitation of the algorithm or business logic). And for the program to work correctly, it is important for us to find errors associated with transferring data of the wrong type as early as possible.

Keeping the idea of ​​dynamic duck typing in modern versions of Python (3.6+) supports annotations of variable types, class fields, arguments, and return values ​​of functions:

Type annotations are read by the Python interpreter and are not processed in any way but are available for use from third-party code and are primarily designed for static analyzers.

In this article, I want to explain the basics and give examples of using type annotations and eventually show why it made my life as a…

--

--

Mikhail Raevskiy

Bioinformatician at Oncobox Inc. (@oncobox). Research Associate