Table of Contents
The benefits of static typing
Static typing, which should be contrasted with the dynamic typing that is most commonly used in scripting languages like JavaScript or PHP, guarantees type safety by forcing developers to specify types for variables and functions at compile time. This means that no spelling or type-related errors can occur at runtime, which is key for large projects where efficient bug detection and prevention are critical.
This type of security is especially important in large projects, because the larger a project is, the more difficult it becomes to maintain it. Thus, ensuring type safety is key for large projects because it offers developers a way to catch typing errors before they occur at runtime. This ensures that they do not cause critical problems in the program.
Static typing improves code quality and performance by catching many bugs at compile time instead of at runtime. Catching bugs at compile time saves developers and QA testers a lot of time because they don’t have to go into complicated testing procedures and environments. This, in turn, ensures that development is faster.

Python developers want static typing
According to data from PyData 2016, all but 1% of Python developers would prefer static typing over dynamic typing. This makes static typing the de facto choice for professional programmers and enterprise software developers everywhere, which is why it is so important that Python continues to migrate towards static typing in its core libraries. Static typing is how Python developers can guarantee that their codebase will run successfully and reliably, and it’s how they can guarantee that the core libraries used by their own projects are reliable and trustworthy.
Python’s dynamic typing system is known to cause trouble whenever it interacts with anything using the C standard library, whether it be third-party libraries or core Python components. In other words, while Python’s dynamic typing system may be nice to have and a useful feature, it is also a problem because of its inability to check types as they are entered into code, which leads to problems like memory leaks and incorrect data being used in unexpected ways.
For example, the following code will consume too much memory if the user runs Python 2.7 on a 32-bit system:
import sys import os sys . path . append ( ‘/tmp’ , ( ‘hello’ , ‘world’ )) os . path . remove ( ‘/tmp’ )
It will fail to delete the path ‘/tmp/hello’. The reason why it fails is that ‘os.path.remove’ expects a file-like object in this case, not a string.
Similarly, we have the following example of incorrect usage of ‘sys.path’ :

What this means for the future of Python
As Python continues to grow and evolve as a programming language, it is increasingly important that it remains a viable option for enterprise software developers. This is especially true in terms of the core language itself, where developers are – and will continue to be – critical stakeholders. If Python does not provide developers with the tools they need to write reliable code, then Python will remain a niche language with limited market penetration and low long-term adoption. Developers deserve the best tools to ensure that their codebase is reliable and can be successfully deployed in an enterprise-level environment, regardless of whether they are using Python 2 or 3. It is imperative that Python maintainers keep their eyes on the future and think about how static typing can benefit every user of the language.
Many developers interested in static typing are not Python developers, and most Python developers do not care about static typing. This article is for the latter group. It assumes familiarity with both dynamic and static typing, including the advantages that dynamic typing can bring to software development (at a high level). If you have no interest in either camp, then feel free to skip this article; it is not for you. If you do care about static typing, please read on.
What is Python?

How to implement static typing in your own projects
As discussed in the PyData 2016 survey, simply converting the Python language to static typing won’t guarantee that everyone will get what they want from the language. Dynamic typing is still the default and the preferred option for most people, so any efforts to make Python a more effective programming language will have to come from other areas. That’s not to say that static typing isn’t a worthwhile goal, but it is important that Python continues to evolve as a language, encouraging developers to use the strongest tools available.
Python is a high-level, general-purpose programming language. It aims to be easy to learn and use across a wide range of applications, while still being highly capable and powerful. Python programs tend to be short and readable, yet very flexible. This paper will not teach you the syntax of Python or the common basics of computer science. Instead, it will teach you how to write Python code that helps improve your own understanding of how static typing works in practice.
This is a reference for people who want to learn how to write Python code that uses static typing. It should be read alongside the Python Static Types section of the language reference, which provides more technical details about the language itself. The paper is intended to help you write better code, not to make you more proficient with Python.
In this paper, we’ll focus on using static typing in your own projects: what it is, when it’s useful, and how to use it yourself. As we’ll see, static typing tools are relatively new and experimental, so they require some extra research before you can use them in your own code. This is an ongoing process, so the tools described here may change at any time. However, with a little effort on your part you should be able to start writing Python code that uses static typing features right away.