Skip to Content
Robust Python
book

Robust Python

by Patrick Viafore
July 2021
Intermediate to advanced
378 pages
9h 35m
English
O'Reilly Media, Inc.
Book available
Content preview from Robust Python

Chapter 6. Customizing Your Typechecker

Typecheckers are one of your best resources for building robust codebases. Jukka Lehtosalo, the lead developer of mypy, offers a beautifully concise definition of typecheckers: “In essence, [a typechecker] provides verified documentation.”1 Type annotations provide documentation about your codebase, allowing other developers the ability to reason about your intentions. Typecheckers use those annotations to verify that the documentation matches the behavior.

As such, a typechecker is invaluable. Confucius once said, “The mechanic, who wishes to do his work well, must first sharpen his tools.”2 This chapter is all about sharpening your typechecker. Great coding techniques can get you far, but it’s your surrounding tooling that takes you to the next level. Don’t stop with just learning your editor, compiler, or operating system. Learn your typechecker too. I will show you some of the more useful options to get the most out of your tools.

Configuring Your Typechecker

I will focus on one of the most popular typecheckers out there: mypy. When you run a typechecker in an IDE (such as PyCharm), it typically runs mypy underneath the hood (although many IDEs will allow you to change the default typechecker). Anytime you configure mypy (or whatever your default typechecker is), your IDE will use that configuration as well.

Mypy offers quite a few configuration options to control the typechecker’s strictness, or the amount of errors reported. The stricter ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Dead Simple Python

Dead Simple Python

Jason C. McDonald
Fluent Python

Fluent Python

Luciano Ramalho

Publisher Resources

ISBN: 9781098100650Errata PageSupplemental Content