Skip to content

Fill in the missing type annotations in backend.cffi.* - #2215

Merged
minrk merged 9 commits into
zeromq:mainfrom
jorenham:typing/backend/coverage
Nov 3, 2026
Merged

minrk merged 9 commits into
zeromq:mainfrom
jorenham:typing/backend/coverage

Conversation

@jorenham

@jorenham jorenham commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

This increase type coverage by filling in the missing annotations for the public-facing symbols in the submodules of zmq.backend.cffi.

According to pyrefly coverage check --public-only (and excluding zmq/tests), this increases type coverage by 7.65%, for a grand total of 93.17% ( 🎉 ).
The remanining untyped typables live in devices, eventloop, green, log, and sugar. My plan is to have a go at those next, with that oh-so-sweet 100% type coverage as (intermediate) life goal (see https://jorenham.github.io/typestats/dashboard/report/#pyzmq for details and some fancy pie charts).

No behavior changes (modulo some trivial asserts for type narroing purposes to appease mypy).

Oh and because Python 3.9 is still supported I had to use __future__.annotatiions imports. So we can get rid of those once py39 support is dropped (it'd require stringifying some type-check-only annotations though, such as Buffer).


No AI touched the code. I only used AI to review the annotations that I wrote myself and I'm pretty sure I'm human.

@jorenham

Copy link
Copy Markdown
Contributor Author

CI could use a rerun

@minrk minrk closed this Nov 3, 2026
@minrk minrk reopened this Nov 3, 2026
@minrk minrk closed this Nov 3, 2026
@minrk minrk reopened this Nov 3, 2026
@minrk minrk changed the title FIll in the missing type annotations in backend.cffi.* Fill in the missing type annotations in backend.cffi.* Nov 3, 2026
@jorenham

jorenham commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Any | None isn't valid or necessary

That's not quite true, as explained in the typing spec (https://typing.python.org/en/latest/spec/concepts.html#union-types):

The union T | Any is not reducible to a simpler form. It represents an unknown static type with lower bound T. That is, it represents an unknown set of objects which may be as large as object, or as small as T, but no smaller.

@minrk

minrk commented Nov 3, 2026

Copy link
Copy Markdown
Member

In this particular case, I think it's fine, because it doesn't reduce it at all or narrow anything. It's also invalid syntax on 3.9, causing the cffi backend to fail to import. I realize adding from __future__ import annotation would also have done it.

@minrk
minrk merged commit 82fa917 into zeromq:main Nov 3, 2026
19 of 20 checks passed
@minrk

minrk commented Nov 3, 2026

Copy link
Copy Markdown
Member

Thanks so much for your contributions and patience!

@jorenham

jorenham commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks so much for your contributions and patience!

Happy to help :)

@jorenham
jorenham deleted the typing/backend/coverage branch November 3, 2026 23:52
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