Why do this on beets, and not on something already typed?
My TypeScript strict post ends with an admission: I meant to do a mypy pass and dropped it, because a small repo wouldn't have given me a number I could stand behind. This is that pass, on a repo big enough to argue with.
The constraints were the same. A real Python project, not a toy. Somewhere between 10,000 and 60,000 lines. Already running mypy in CI, so the starting point is a green build, but not already strict. That last one ruled out most of what I tried first: Scrapy's pyproject.toml opens with strict = true, and plenty of others are the same.
beets fit. It's the music library manager (beetbox/beets), its first commit is from May 2008, it runs mypy on every pull request, and its config is permissive: ignore_missing_imports = true plus a couple of namespace settings. The beets and beetsplug packages at tag v2.9.0 (commit 018dba0, April 2026) are 155 files and 47,181 lines, 20,690 in the core and 26,491 in plugins. I left test/ out.
Why v2.9.0 and not the newest release, v2.14.1? I started there, and kept it once I saw what it bought me: five months of later history to check my verdicts against. If I call something a bug and the maintainers fixed it later, that's a better witness than my opinion.
Setup, all on a Linux box: Python 3.13.18, a venv built with uv, beets installed editable with every extra that installs without system libraries, the seven stub packages its typing group lists, and mypy 2.4.1. Each full run took about 9 seconds.
What does the default config report before anyone turns anything on?
Nine errors. Isn't CI green? It is, and that surprised me. The lockfile pins mypy 1.20.0, and with that version I got 2. The other 7 are what moving to mypy 2.x costs on its own: 2.0 turned on local_partial_types and strict_bytes by default, according to its changelog. Switch those two back off and 2.4.1 drops to 3.
So, same lesson as TypeScript 7 in the sibling post. You don't avoid the bill by not opting in. A compiler upgrade sends part of it anyway. I treat those 9 as the baseline and count everything below as new on top of them.
What does each strict flag cost alone?
mypy 2.4.1 lists 13 flags under --strict. I ran each one alone against the untouched tree, then all of them together.
| Flag | New errors | Files |
|---|---|---|
| disallow_untyped_defs | 1,442 | 130 |
| disallow_incomplete_defs | 277 | 54 |
| disallow_untyped_calls | 231 | 63 |
| check_untyped_defs | 148 | 47 |
| warn_return_any | 49 | 21 |
| no_implicit_reexport | 6 | 4 |
| warn_unused_ignores | 5 | 4 |
| strict_equality | 2 | 2 |
| extra_checks, warn_redundant_casts, disallow_untyped_decorators, disallow_subclassing_any, disallow_any_generics | 0 each | 0 |
--strict |
2,911 | 138 |
Five flags cost nothing. One of those zeros is cheating: the project already sets allow_any_generics = false, so disallow_any_generics has nothing left to find. The other four are genuinely free.
The bigger difference from TypeScript is the arithmetic. On ioredis the per-flag rows summed to 420 against 405 for the whole set, because one expression can trip two flags. Here the rows sum to 2,160 and --strict gives 2,911. The whole is bigger than its parts. The reason is check_untyped_defs: by default mypy doesn't look inside a function that has no annotations, so disallow_untyped_calls alone only sees calls from typed code, 231 of them. Open the bodies, as --strict does, and it sees 1,258. I ran the pair together to be sure: 1,408 new errors, against 379 for the two flags run apart.
Scaled to size, beets has about 62 strict errors per thousand lines. ioredis had 20. That isn't a verdict on either team. A Python function with no annotations is legal and normal. A TypeScript file has types whether you wrote them or not.
What are 2,911 errors made of?
Mostly one thing, and can you guess it? no-untyped-def is 1,442 errors and no-untyped-call is 1,258: 2,700 together, 93 percent. Neither is a finding about behavior. They say a function has no annotations, or that typed code calls one that doesn't.
I checked who owns the callees. Matching names against def and class names in the tree, 1,251 of the 1,258 untyped calls go to beets' own functions. One constructor, Subcommand, accounts for 67. Annotate the top handful and hundreds of errors disappear without anyone touching a call site. Is that a stub problem? No. It's a to-do list.
Distribution follows the TypeScript shape, only steeper. Five files hold 805 of the errors: the MPD-compatible server in beetsplug/bpd/__init__.py with 365, library/models.py with 138, the coroutine scheduler util/bluelet.py with 110, importer/tasks.py with 100, test/helper.py with 92. Thirteen files have 50 or more each and together carry 1,319. The plugin directory carries 1,813 of the 2,911.
Which strict errors were real bugs?
To find out, I had to get the annotation noise out of the way. With --allow-untyped-defs --allow-incomplete-defs --allow-untyped-calls added to --strict, 210 new errors remain. I drew 30 at random (seed in the example folder) and classified each by reading the code around it.
Half of it is noise, by which I mean the code is correct and mypy can't see why: a variable reused for a str and then bytes, an attribute that's None until an event handler sets it, == on an Any operand returning Any. Ten are missing or too-narrow annotations, like options = {} or an alias that types every archive opener as taking one argument when all of them accept mode=. Two are library returns typed Any (requests' Response.json(), requests_oauthlib). Two are # type: ignore comments nothing needs any more. One of those guards a mypy bug whose fix, per its own comment, was "not yet released". It has shipped since.
And one is a bug. In beetsplug/smartplaylist.py:
if item_uri not in m3us[m3u_name]: # item_uri is bytes
m3us[m3u_name].append(PlaylistItem(item, item_uri))
m3us[m3u_name] is a list of PlaylistItem objects, so a bytes value is never in it and the duplicate check never fires. mypy says Non-overlapping container check (element type: "bytes", container item type: "PlaylistItem"). I wrote a test where two playlists share one m3u file and match the same track: v2.9.0 writes the path twice. The maintainers fixed it in commit 6b3241f4, first released in v2.11.0, with a message that describes the same mistake: deduplicate "instead of comparing bytes to PlaylistItem objects". At v2.14.1 my test writes the path once.
That error came from strict_equality, and so did the only other one that flag reported, which wasn't in my sample. In beetsplug/playlist.py the m3u file is opened in binary mode, so line[0] is an int, and line[0] == "#" is never true. The comment-skipping branch is dead. Feed it a playlist with #EXTM3U and #EXTINF lines and the query keeps 3 paths instead of 1. That's still true at v2.14.1, and the same line is on master today.
How often does a checker go two for two? The flag with the smallest non-zero bill had a 100 percent hit rate. Two errors, two defects. Small numbers, I know, but I'd still rather start there than with the 1,442.
Why didn't beets' own per-module config catch any of this?
Because it doesn't run. Who would guess that from reading it? setup.cfg at v2.9.0 ends like this:
[[mypy-beets.plugins]]
disallow_untyped_decorators = true
check_untyped_defs = true
Double brackets are TOML syntax. In an INI file, configparser reads the section name as [mypy-beets.plugins], brackets included. mypy only looks at sections whose name starts with mypy-, so it skips this one, and --warn-unused-configs stays silent too. I checked rather than assumed: I appended a function with x: int = "not an int" to beets/plugins.py. The shipped config reported nothing but an annotation-unchecked note. The same file with single brackets reported the assignment error.
The sections arrived in April 2025, in commit 43301c4c. By v2.14.1 there are six of them, four reading strict = true, and they're still on master. Fixing the brackets isn't enough either. In mypy 2.4.1, strict = true inside a per-module section calls the same routine as the global flag, so it turns strict on for every module. I tested that at v2.14.1: one such section produced 170 errors, identical to --strict on the whole tree.
That's my claim you're free to dispute: a per-module ratchet that nobody has watched fail is not a ratchet. This one sat in the repo for 19 months looking like progress.
What does a working ratchet look like?
Two tiers, like the TypeScript version, but the cheap tier is cheaper here. I made one patch against v2.9.0: the two strict_equality fixes (one line each) and the 5 stale ignores deleted. Seven changed lines in 6 files. The beets test suite on the patched tree: 2,297 passed, 144 skipped, and 1 failure that fails identically without my patch, because the container runs as root and the test checks write permissions.
After that, six strict flags cost zero and go global. Then I reran --strict per file: 18 of 155 modules have no strict errors, 2,821 lines in all. Those get the full set of per-module flags:
[tool.mypy]
allow_any_generics = false
ignore_missing_imports = true
disallow_subclassing_any = true
disallow_untyped_decorators = true
warn_redundant_casts = true
warn_unused_ignores = true
extra_checks = true
strict_equality = true
[[tool.mypy.overrides]]
module = ["beets.dbcore", "beets.util.color", "beetsplug.lastgenre.client"] # 18 in the real file
disallow_untyped_defs = true
disallow_incomplete_defs = true
disallow_untyped_calls = true
check_untyped_defs = true
warn_return_any = true
implicit_reexport = false
Notice anything missing? There's no strict = true in the override, for the reason above. warn_redundant_casts can only be set globally, which is fine at zero.
With this config the whole tree reports the same 9 baseline errors in 8.9 seconds, versus 9.2 for a full --strict run. Then I pasted a sloppy four-line function, an untyped parameter plus a bytes in list[str] test, into two places. In beets/util/color.py, a ratcheted module, mypy reported both no-untyped-def and comparison-overlap. In beets/util/__init__.py, which isn't ratcheted yet, it reported only comparison-overlap. That's the intended shape: the cheap flags guard everyone, the expensive ones guard the modules that have already paid.
The ratchet moves by editing the module list. A module that reaches zero gets added. Nothing ever comes off.
What did beets actually do afterwards?
This is where the older tag paid off. Did they follow a plan like mine? Partly. Between v2.9.0 and v2.14.1 there are 1,339 commits, and 135 have "typ" in the subject line. A couple of those are typo fixes; twenty I picked at random were all about types. At v2.14.1, mypy 2.4.1 under the project config reports 0 errors, and --strict reports 170 across 62 of 167 files. 105 files, 18,232 lines, already pass strict. From 2,911 to 170 in five months.
They didn't get there with mypy flags, though. They turned on ruff's ANN rules (flake8-annotations), with ANN401 ignored because, in their own comment, "we use Any type in the codebase". # type: ignore comments went from 30 to 66. A lint rule that demands annotations got them the annotations. It didn't buy strict_equality, which is still off, and the playlist bug it would have flagged is still there. At v2.14.1, strict_equality reports one more comparison in the musicbrainz plugin, the module one of those dead strict = true sections was meant to cover. I didn't work out whether that one is a bug or a type that's missing a value.
What would I do with a codebase like this?
Same order as my twelve CI gates, where type checking sits fourth: the gate is worth running long before it's finished.
- Turn on every flag that costs zero, today. On beets that was six of thirteen after a 7-line patch. They're free now and they stop new mistakes of those kinds the day they land.
- Turn on
strict_equalityfirst among the paid ones. It had the smallest non-zero bill and the best yield I measured. - Treat annotation coverage as a to-do list, not a gate. 2,700 errors that say "no annotations here" don't find bugs; they show where nobody has written types yet. Sort the untyped callees by call count and start at the top.
- Ratchet by module with explicit flags, and test the config. Put a deliberate error in a ratcheted module once and watch CI go red. If it doesn't, you've got beets' setup.cfg.
A # type: ignore count that doubles while annotations land is the Python version of teams suppressing lint rules. I'd put warn_unused_ignores on globally for exactly that reason. At least the stale ones get deleted.
What I didn't measure
- Human time. No hours figure, here or in the TypeScript post.
test/. beets' CI type-checks it; I checked onlybeetsandbeetsplug.- Plugins needing system libraries: PyGObject (bpd, replaygain), dbus-python (metasync) and reflink weren't installed, so with
ignore_missing_importstheir imports becameAny. That likely hides some stub-gap errors. - The labels on the 30-error sample are my judgement on one reading each. Every row has its reason in
sample30.csv. - Whether the musicbrainz comparison at v2.14.1 is a bug.
- Whether ruff's
ANNrules or mypy flags would have been cheaper for the beets team. I can see the outcome, not the effort. - Anything past mypy. No pyright, no runtime type checking.
The scripts, the patch, both reproductions and the ratchet config are in blogs/zero-bugs/examples/mypy-strict-on-an-existing-python-project-beets/, starting with setup.sh.