PythonMastery
In the wild · Dropbox

How Dropbox type-checked 4 million lines of Python

Dropbox added type hints to about 4 million lines of Python over three years. What pushed them, what slowed them down, and the part any team can copy.

The problem

Dropbox's backend was one of the largest Python codebases anywhere. In their words: "At our scale—millions of lines of Python—the dynamic typing in Python made code needlessly hard to understand and started to seriously impact productivity."

The everyday version of that problem: you open a function and can't tell what it returns, what its arguments should be, or whether it might hand back None.

What they did

They didn't annotate everything at once. Python's type hints are optional, so annotated and unannotated code run side by side, and the checker only reports on the parts that have hints.

What slowed them down, and the fix

As coverage grew, checking the whole codebase from scratch took over 15 minutes. They fixed it in layers:

The part any team can copy

You don't need 4 million lines to get the benefit. Add hints where a reader most often has to guess, like the functions everyone calls:

python
def total_cents(prices: list[float]) -> int:
    return round(sum(prices) * 100)

print(total_cents([19.99, 5.01]))
print(total_cents.__annotations__)
output
2500
{'prices': list[float], 'return': <class 'int'>}

The hints change nothing at run time; they're read by tools like mypy and by your editor. That's why adding them gradually works: nothing breaks while half the code has them and half doesn't.

Their closing advice: "If you aren't using type checking in your large-scale Python project, now is a good time to get started—nobody who has made the jump I've talked to has regretted it."

the tipTake this away

Add type hints gradually, starting where code is hardest to read. Learn it properly: Type Hints: Industrial-Grade Python.

Sources

every claim above comes from these