Skip to content

Typing fixes and improvements for Socket, Frame, and Context#2184

Open
jorenham wants to merge 3 commits into
zeromq:mainfrom
jorenham:typing/backend/coverage
Open

Typing fixes and improvements for Socket, Frame, and Context#2184
jorenham wants to merge 3 commits into
zeromq:mainfrom
jorenham:typing/backend/coverage

Conversation

@jorenham

@jorenham jorenham commented May 19, 2026

Copy link
Copy Markdown
Contributor

This PR was initially intended for filling in the missing public type annotations in zmq.backend, like #2183 and #2182. But while doing so, I noticed several typing issues: incorrect return types, incompetible overrides, incorrect type variable variance, and some minor overload issues. Because, you see, mypy completely ignores unannotated functions by default. So by annotating these methods, several hidden typing issues surfaced. Those issues weren't as simple as fixing one thing; I had to fix a whole bunch of stuff to get everything nice and consistent.
This unfortunately also caused this to not be as self-contained as I had hoped it would be. I don't think there's a good way to split this up though, or at least, not in a way that mypy will like.

FWIW: I had Claude Opus 4.7 review (but not touch) every change here. After iterating like this for a bit, it now seems to fully agree with the changes. But don't worry, those reviews is all I used AI for :)

Besides the typing fixes, this also increases type coverage by 4.07%.


Thanks for submitting a PR!

LLM/AI contributions are not accepted.

Please make sure:

  • I wrote this (no AI-generated code or text is included in this PR or its description)
  • any code changes are tested, if possible

@jorenham
jorenham marked this pull request as draft May 19, 2026 16:48
@jorenham

Copy link
Copy Markdown
Contributor Author

Hmm apparently I messed up somewhere... Marking this as draft until I fixed it

@jorenham

jorenham commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

Well, as it turns out, these new mypy errors uncovered actual bugs in the examples. For example:

$ python examples/poll/reqrep.py 
Running polling tests for REQ/REP sockets...
Traceback (most recent call last):
  File "/home/joren/Workspace/pyzmq/examples/poll/reqrep.py", line 37, in <module>
    s2.send('msg1')
    ~~~~~~~^^^^^^^^
  File "/home/joren/Workspace/pyzmq/zmq/sugar/socket.py", line 713, in send
    return super().send(data, flags=flags, copy=copy, track=track)
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "zmq/backend/cython/_zmq.py", line 1152, in zmq.backend.cython._zmq.Socket.send
    def send(self, data, flags=0, copy: bint = True, track: bint = False):
  File "zmq/backend/cython/_zmq.py", line 1197, in zmq.backend.cython._zmq.Socket.send
    raise TypeError("unicode not allowed, use send_string")
TypeError: unicode not allowed, use send_string

I'll fix the examples as well then.

@jorenham
jorenham force-pushed the typing/backend/coverage branch from e566a08 to 53c7ee2 Compare July 9, 2026 19:05
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