A practical guide to testing Pyrefly on your own code, measuring cold and warm times, and judging diagnostic quality before migrating.
Google has announced it is replacing its long-standing type checker Pytype with Pyrefly, an open-source tool that originated at Meta. According to Google's open-source blog, the reasons are increased speed, greater accuracy, and lower infrastructure costs.
However, the numbers from someone else's monorepo aren't your numbers. In this guide, we propose a simple method to compare Pyrefly with what you currently use in your own codebase, without relying on third-party benchmarks.

Why it's worth trying
Pytype analyzed compiled bytecode instead of source code abstract syntax trees. Google explains that this made it increasingly expensive to keep up with new typing PEPs, because bytecode changes between Python versions.
Pyrefly, written in Rust, is about ten times faster than Pytype, according to Google. It reduces incremental rebuild latency by up to 98% and cuts maximum compute cost by over 80%. It also passes approximately 97% of the tests in the Python typing conformance suite. These are Google's internal figures: treat them as hypotheses to verify, not as guarantees.
What you need
- A Python project with type annotations, even if partial.
- An isolated virtual environment to avoid touching project dependencies.
- The checker you currently use (mypy, Pyright, or Pytype) for a fair comparison.
- A test branch and a stopwatch, for example, your shell's
timecommand.
The code and documentation are available in the official repository. Refer to it for installation and current options, as specific commands may vary between versions.
Steps for comparison
- Create a test branch and a clean virtual environment.
- Install Pyrefly following the official documentation and verify that it starts.
- Run your current checker with an empty cache and record the cold time.
- Repeat the execution without changes to measure the warm time.
- Do the same with Pyrefly, cold and warm, on exactly the same tree.
- Modify a single file and measure incremental checking with each tool.
- Review the diagnostics: how many are real errors, how much is noise, and how clear is the source of the failure.
# Indicative outline; adapt commands to your tool and version
rm -rf .mypy_cache
time <your-current-checker> # cold
time <your-current-checker> # warmWhat to expect and what to watch out for
Don't expect all tools to agree on the same errors: each interprets some edge cases differently, so a migration might uncover new warnings or make others disappear. In the news comments, there was debate with Ty and mypy; one reader noted that mypy remains very competitive in incremental checking, and another, that Ty was not yet as mature as Pyrefly.

Once you have the results, decide based on criteria that matter to your team: edit wait time, continuous integration cost, and message clarity. There's no universal shortcut; for a small project, the difference might not justify the change.
Original source: infoq.com
Article generated with AI.larebelion



Comentarios
Publicar un comentario