Skip to Content
Hypermodern Python Tooling
book

Hypermodern Python Tooling

by Claudio Jolowicz
June 2024
Intermediate to advanced
270 pages
6h 40m
English
O'Reilly Media, Inc.
Content preview from Hypermodern Python Tooling

Chapter 9. Linting with Ruff and pre-commit

In 1978, Stephen C. Johnson, a researcher at Bell Labs, wrote a program that could detect a number of bugs and obscurities in C code. He named the program after the fluff on your pullover when you take it out of the washing machine: Lint. It was to become the first in a long line of linters, programs that analyze source code and point out problematic constructs.

Linters don’t run a program to discover issues with it; they read and analyze its source code. This process is known as static analysis, as opposed to runtime (or dynamic) analysis. It makes linters both fast and safe—​you needn’t worry about side effects, such as requests to production systems. Static checks can be smart and also fairly complete—​you needn’t hit the right combination of edge cases to dig up a latent bug.

Note

Static analysis is powerful, but you should still write tests for your programs. Where static checks use deduction, tests use observation. Linters verify a limited set of generic code properties, while tests can validate that a program satisfies its requirements.

Linters are also great at enforcing a readable and consistent style, with a preference for idiomatic and modern constructs over obscure and deprecated syntax. Organizations have adopted style guides for years, such as the recommendations in PEP 8 or the Google Style Guide for Python. Linters can function as executable style guides: by flagging offending constructs automatically, they keep code ...

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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Learning Python, 6th Edition

Learning Python, 6th Edition

Mark Lutz

Publisher Resources

ISBN: 9781098139575Errata Page