Skip to content

ci: add Pyrefly type validation/code coverage and bug fixes#410

Open
danudey wants to merge 7 commits into
newAM:mainfrom
danudey:add-pyrefly-type-validation
Open

ci: add Pyrefly type validation/code coverage and bug fixes#410
danudey wants to merge 7 commits into
newAM:mainfrom
danudey:add-pyrefly-type-validation

Conversation

@danudey

@danudey danudey commented Oct 17, 2025

Copy link
Copy Markdown
Contributor

Pyrefly is a new, incredibly fast, type checker written in Rust by Meta. This PR adds pyrefly as a check, and also fixes all the existing issues it finds.

A few notes:

  • There are a few cases where, for the sake of brevity, we explicitly create new types to satisfy the type checker rather than e.g. scattering int(foo) everywhere it's used. This also has the side effect of making it clear which type you're expecting based on which parameter you're using.
  • For the windows VCP module, type checking is obviously broken on my local since I'm not testing on Windows. I've yet to determine how to conditionally type check a file (i.e. to not do type checks on vcp_windows.py if we're not on Windows), so for the few accesses which do not eist on Windows I moved those to separate centralized 'aliases' so I could add pyrefly:ignore to those specific lines rather than scattering them all over the codebase. Not sure if this is the right call, willing to change this up if it feels yucky.

Edit

Was working on expanding code coverage and found (well, Claude found) two pre-existing bugs that were easy to fix:

In LinuxVCP.rate_limt, the delay is computed as rate_delay = self.CMD_RATE - time.time() - self.last_set, which
takes the 50ms constant and subtracts the last-set timestamp and the value of time.time(), meaning it's always negative. Simple parenthesis change fixed.

Also, LinuxVCP.write_bytes, in the missing file descriptor branch we create the VCPIOError("unable write to I2C bus: no open file descriptor found") exception but we don't actually raise it. Another simple fix.

Wanted to fix these so that new unit tests wouldn't end up testing invalid behavior and then require fixing in a separate PR.

On top of this, added a bunch of code coverage (as mentioned) for linux_vcp.py; if this feels too far out of scope for this PR, I can refactor it out.

@newAM

newAM commented Oct 25, 2025

Copy link
Copy Markdown
Owner

Thanks for all the fixes! Can you resolve the conflict?

I think there may also be some syntaxes that need to be changed for older python versions, I try to maintain support for all versions still getting official security updates. Feel free to ignore 3.9 though, support for that version ends this month.

@danudey

danudey commented Oct 25, 2025

Copy link
Copy Markdown
Contributor Author

Sounds good, I'll switch over to testing with 3.10 then and see if anything needs fixing then update the branch again.

@danudey danudey force-pushed the add-pyrefly-type-validation branch from fdc93ec to 10c4be0 Compare March 19, 2026 22:04
@danudey danudey force-pushed the add-pyrefly-type-validation branch from a422bda to 549e095 Compare July 3, 2026 19:14
@danudey danudey changed the title ci: add Pyrefly type validation and fix existing errors ci: add Pyrefly type validation/code coverage and bug fixes Jul 3, 2026
@danudey

danudey commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@newAM A bunch of updates in this PR, outside of the original scope. Let me know if you want me to split this off to preserve context.

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.

2 participants