Detecting Problems Early

Intuitive Python — by David Muller (12 / 41)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Investigating with pdb Breakpoints | TOC | Formatting and Styling Your Code Consistently 👉

Unlike traditionally compiled languages, Python does not require source code to be compiled into machine code before it is run. Instead, Python accepts source code directly and executes it as is. This means that it is possible for you to, for example, run invalid Python source code that never stands a chance of executing or working.

To reduce this risk, many Python projects run static analysis tools to help them validate and verify source code before trying to run it. What are static analysis tools? Static analysis tools don’t actually run your code, but read it and inspect it for issues that can be found just by browsing the source code itself. Kind of like a friend peering over your shoulder as you type and letting you know when you’ve made a mistake before you’ve even tried to run anything.

In this section we’ll talk about two tools for finding and eliminating bugs in your programs ahead of time: flake8 and mypy.

Running flake8 to Find Errors

The flake8 static analysis tool detects a number of different errors in Python source code and flags them for you to fix.[26] In this section, we’ll highlight a select few errors flake8 detects to help you get a sense of flake8’s benefits.

How Do I Run flake8?

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.