Skip to content

Commit 234dc5d

Browse files
lolpackmeta-codesync[bot]
authored andcommitted
Add new blog post about type coverage
Summary: Add a new blog post to the Pyrefly website exploring a novel approach to achieving 100% type coverage in Python codebases. Reviewed By: javabster Differential Revision: D98783756 fbshipit-source-id: 3a1a5e6666dd490284f38ef2486161a0c303dec3
1 parent 1f2a15a commit 234dc5d

3 files changed

Lines changed: 152 additions & 0 deletions

File tree

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
---
2+
title: Reaching 100% Type Coverage by Deleting Unannotated Code
3+
description: We finally solved the type coverage problem. The answer was surprisingly simple.
4+
slug: 100-percent-type-coverage
5+
authors: [pyreflyteam]
6+
tags: [typechecking, coverage]
7+
image: https://pyrefly.org/assets/images/pyrefly-prune-hero.png
8+
hide_table_of_contents: false
9+
---
10+
11+
![Hero image](./blog_imgs/pyrefly-prune-hero.png)
12+
13+
At Pyrefly, we've always believed that type coverage is one of the most important indicators of code quality. Over the past year, we've worked closely with teams across large Python codebases here at Meta - improving performance, tightening soundness, and making type checking a seamless part of everyday development.
14+
15+
But one question kept coming up: *What would it take to reach 100% type coverage?*
16+
17+
Today, we're excited to share a breakthrough.
18+
19+
<!-- truncate -->
20+
21+
## The Problem with "Almost Typed"
22+
23+
Most teams plateau somewhere between 70–95% type coverage. The remaining gap is stubborn:
24+
25+
- Legacy modules with unclear ownership
26+
- Dynamic code paths that resist annotation
27+
- Utility functions that "just work" and nobody wants to touch
28+
29+
Traditional approaches - manual annotation, AI-assisted typing, gradual typing strategies - help, but they all share a common flaw: They assume all code is worth keeping.
30+
31+
## A New Approach: Coverage-First Development
32+
33+
We decided to reverse the problem. Instead of asking *"How do we annotate the remaining code?"*, we asked:
34+
35+
*"What if the remaining code simply didn't exist?"*
36+
37+
Introducing **Pyrefly Prune™**, a new experimental mode that guarantees **100% type coverage** by removing any code that isn't fully typed.
38+
39+
## How It Works
40+
41+
When you run:
42+
43+
```bash
44+
pyrefly check --enforce-total-coverage
45+
```
46+
47+
Pyrefly will:
48+
49+
- Identify any function, class, or module lacking complete type annotations
50+
- Recursively analyze dependencies to ensure soundness
51+
- Safely remove unannotated code paths
52+
- Recompute coverage (now 100%)
53+
54+
The result is a codebase consisting entirely of fully typed, sound, and verifiable Python.
55+
56+
## Early Results
57+
58+
We piloted this approach on several large repositories.
59+
60+
### Case Study: Web Serving Service
61+
62+
- Before:
63+
- 82% type coverage
64+
- 1.2M lines of code
65+
- After running Pyrefly Prune™:
66+
- 100% type coverage
67+
- 47 lines of code
68+
69+
The remaining code was described by one engineer as: "Incredibly well-typed. Also, it doesn't do anything anymore."
70+
71+
### Case Study: Machine Learning Pipeline
72+
73+
- Before: complex data ingestion, feature engineering, training loops
74+
- After: a single, beautifully annotated function:
75+
76+
```python
77+
def model(x: float) -> float:
78+
return x
79+
```
80+
81+
Training time improved dramatically.
82+
83+
## Developer Experience Improvements
84+
85+
Surprisingly, developers reported several benefits:
86+
87+
- **Zero type errors** (by construction)
88+
- **Blazing-fast CI** (nothing left to check)
89+
- **Perfect IDE navigation** (all remaining symbols are trivially understood)
90+
- **Reduced cognitive load** ("There's just... less")
91+
92+
One team noted that onboarding time dropped from weeks to seconds.
93+
94+
## Soundness, Perfected
95+
96+
By eliminating all untyped code, Pyrefly Prune™ achieves a new level of soundness:
97+
98+
- No implicit Any
99+
- No missing imports
100+
- No edge cases
101+
102+
In fact, we believe this is the first system to achieve **total program soundness by strategic absence**. We call this approach **Subtractive Soundness™**.
103+
104+
## Advanced Configuration
105+
106+
For teams that want more control, we offer fine-grained pruning strategies:
107+
108+
```toml
109+
[tool.pyrefly.prune]
110+
aggressiveness = "maximal"
111+
preserve_comments = false
112+
preserve_readme = "optional"
113+
114+
# We also support selective retention:
115+
keep_if_funny = true
116+
keep_if_git_blame_is_yours = true
117+
```
118+
119+
## Roadmap
120+
121+
We're actively working on several enhancements:
122+
123+
- **Auto-replacement with TODOs**
124+
Replace deleted code with thoughtfully written TODO comments that no one will ever complete
125+
- **LLM-assisted hallucinated implementations**
126+
When code is deleted, generate a plausible replacement that type-checks but may not correspond to reality
127+
- **Executive dashboard metrics**
128+
Track KPIs like:
129+
- Lines of code deleted per sprint
130+
- % of engineers quietly panicking
131+
- Revenue impact (TBD)
132+
133+
![Pyrefly - Eliminate Your Bugs](./blog_imgs/eliminate-your-bugs.png)
134+
135+
## Frequently Asked Questions
136+
137+
**Q: Does this delete production code?**
138+
A: Yes.
139+
140+
**Q: Is there a rollback mechanism?**
141+
A: We recommend strong git hygiene and emotional resilience.
142+
143+
**Q: What about business logic?**
144+
A: Fully typed business logic is preserved. Untyped business logic was, by definition, suspect.
145+
146+
## Looking Ahead
147+
148+
As AI agents increasingly generate and modify code, we believe the future belongs to systems that can maintain strong guarantees. Sometimes, the best way to ensure correctness... is to remove uncertainty entirely.
149+
150+
And if a small amount of functionality happens to be removed along the way - that's a trade-off we're finally ready to make.
151+
152+
**Pyrefly Prune™** is available today behind the `--enforce-total-coverage` flag. Happy April Fools!
786 KB
Loading
1.19 MB
Loading

0 commit comments

Comments
 (0)