Skip to content

Add pyrefly as a second type checker - #1017

Open
jonathan343 wants to merge 1 commit into
developfrom
chore/add-pyrefly
Open

jonathan343 wants to merge 1 commit into
developfrom
chore/add-pyrefly

Conversation

@jonathan343

@jonathan343 jonathan343 commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This adds pyrefly 1.5.2 as a second type checker, run by make check-py after pyright. In an audit of pyright, mypy, ty and pyrefly on this repo, pyrefly reported real defects that pyright misses. Some implementations of the URI protocol make its mutable attributes read-only. ShapeSerializer.flush has only a docstring, so pyrefly treats it as abstract, and every serializer without its own flush can't be instantiated. Pyright stays, because pyrefly has nothing like --verifytypes or pyright's strict-mode checks for unknown types.

The errors pyrefly reports today are recorded in pyrefly-baseline.json, so the check fails only on new errors. Most of its 162 entries come from three root causes: flush (68), a test protocol in smithy-http that declares ID and SCHEMA without values (51), and the URI and PropertyKey overrides (18). Follow-up PRs will fix those errors and pyrefly's 6 existing warnings, and consider stricter settings.

Decisions

  1. Each package has its own [tool.pyrefly] config. Every package has a top-level tests package, so one config for the whole repo would see 11 modules named tests. With a config in each package, pyrefly check packages/*/ checks each package as a separate project with search-path = [".", "src"]. The configs honor the existing # pyright: ignore comments, so pyrefly skips the lines pyright already ignores.
  2. Baseline entries use column-ordered matching. In the default column mode, an entry matches on file, error kind and column, so one entry hides any number of errors. A second _BlobRecorder() in a file that already has baseline entries passed the check in that mode and fails in this one. Entries for errors that have since been fixed also fail the check (--error-stale-baseline). make pyrefly-baseline removes them, and no make target adds entries.

Testing

Adding a new error to a file that already has baseline entries fails the check:

printf '\n\ndef test_extra() -> None:\n    serializer = _BlobRecorder()\n    del serializer\n' >> packages/smithy-core/tests/unit/test_serializers.py
make check-py
ERROR Cannot instantiate `_BlobRecorder` because the following members are abstract: `flush` [bad-instantiation]
  --> packages/smithy-core/tests/unit/test_serializers.py:41:31
   |
41 |     serializer = _BlobRecorder()
   |                               ^^
 INFO 1 error (6 warnings, 544 suppressed)
make: *** [check-py] Error 1

Fixing flush fails the check because 68 entries are now stale. make pyrefly-baseline then removes them and leaves 94.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Run pyrefly in check-py with a per-package config, and record existing
errors in pyrefly-baseline.json so only new errors fail the check.
@jonathan343
jonathan343 marked this pull request as ready for review December 6, 2026 07:10
@jonathan343
jonathan343 requested a review from a team as a code owner December 6, 2026 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant