Skip to content

Pass mypy checks (in lint job, via tox)#918

Merged
PierreF merged 18 commits into
eclipse-paho:masterfrom
JamesParrott:pass_mypy
Jun 14, 2026
Merged

Pass mypy checks (in lint job, via tox)#918
PierreF merged 18 commits into
eclipse-paho:masterfrom
JamesParrott:pass_mypy

Conversation

@JamesParrott

@JamesParrott JamesParrott commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #917, #919, & #920

Created PRs to fix those two test failures, and rebased this PR onto them both. I'm not sure why there is a test failure on tear down (on Python 3.8 only) - I'll look into it. The test 'failure' on Python 3.7 is probably because Github's setup Python action no longer supports Python 3.7

There is only one non-trivial change to run time code - coercing result to bytes from bytesarray, to ensure _WebSocketWrapper._recv_impl's returned values really are bytes (its declared return type). The two trivial run time changes are to re order a simple and expression to assist mypy, and to import overload from typing. All other changes are to type annotations only.

Before I renamed the branch:
image

  • SocketLike.send now explicitly accepts bytearray
  • An expression was reordered so that mypy could infer self._socket was not None
  • _force_bytes was generalised, and given some overloads, to assist mypy's type narrowing
  • MQTTMessage.payload and Client._will_payload have been annotated to explicitly also support bytesarray now, as well as bytes.

Fixes:  src\paho\mqtt\client.py:1698: error: Item "None" of "socket | None" has no attribute "recv"  [union-attr]
Matches return type of _encode_payload.  Fixes:  src\paho\mqtt\client.py:1781: error: Incompatible types in assignment (expression has type "bytes | bytearray", variable has type "bytes")  [assignment]
Fixes:
src\paho\mqtt\client.py:3444: error: Argument 2 to "_packet_queue" of "Client" has incompatible type "bytearray"; expected "bytes"  [arg-type]
src\paho\mqtt\client.py:3572: error: Argument 2 to "_packet_queue" of "Client" has incompatible type "bytearray"; expected "bytes"  [arg-type]
src\paho\mqtt\client.py:3610: error: Argument 2 to "_packet_queue" of "Client" has incompatible type "bytearray"; expected "bytes"  [arg-type]
src\paho\mqtt\client.py:3652: error: Argument 2 to "_packet_queue" of "Client" has incompatible type "bytearray"; expected "bytes"  [arg-type]
src\paho\mqtt\client.py:3701: error: Argument 2 to "_packet_queue" of "Client" has incompatible type "bytearray"; expected "bytes"  [arg-type]
Fixes:
src\paho\mqtt\client.py:2233: error: Incompatible types in assignment (expression has type "bytes | bytearray", variable has type "bytes")  [assignment]
src\paho\mqtt\client.py:3444: error: Argument 2 to "_packet_queue" of "Client" has incompatible type "bytearray"; expected "bytes"  [arg-type]
src\paho\mqtt\client.py:3572: error: Argument 2 to "_packet_queue" of "Client" has incompatible type "bytearray"; expected "bytes"  [arg-type]
src\paho\mqtt\client.py:3610: error: Argument 2 to "_packet_queue" of "Client" has incompatible type "bytearray"; expected "bytes"  [arg-type]
src\paho\mqtt\client.py:3652: error: Argument 2 to "_packet_queue" of "Client" has incompatible type "bytearray"; expected "bytes"  [arg-type]
src\paho\mqtt\client.py:3701: error: Argument 2 to "_packet_queue" of "Client" has incompatible type "bytearray"; expected "bytes"  [arg-type]
src\paho\mqtt\client.py:4628: error: Module has no attribute "AF_UNIX"; maybe "AF_IPX"?  [attr-defined]
src\paho\mqtt\client.py:4921: error: Incompatible types in assignment (expression has type "bytearray", variable has type "bytes")  [assignment]

@PierreF PierreF left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that pass, it would have been my next tasks after #916.

Comment thread .github/workflows/tox.yml Outdated
Comment thread tests/lib/conftest.py Outdated
Co-authored-by: Pierre Fersing <pierref@pierref.org>

@pswsm pswsm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor style diffs, feel free to ignore them.

Comment thread src/paho/mqtt/client.py Outdated
Comment thread src/paho/mqtt/client.py Outdated
@JamesParrott JamesParrott requested a review from PierreF June 14, 2026 11:38
@PierreF PierreF merged commit c4af656 into eclipse-paho:master Jun 14, 2026
10 checks passed
@JamesParrott JamesParrott deleted the pass_mypy branch June 15, 2026 08:47
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.

The Mypy check is failing (during the lint job, run via tox)

3 participants