Skip to content

Commit

Permalink
refactor: use paho-mqtt v2.0.0 with type ignores
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanPlasse authored and frederikaalund committed Mar 28, 2024
1 parent 99075ec commit 8321217
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions aiomqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def __init__( # noqa: C901, PLR0912, PLR0913, PLR0915
# Create the underlying paho-mqtt client instance
self._client: mqtt.Client = mqtt.Client(
callback_api_version=CallbackAPIVersion.VERSION1,
client_id=identifier,
client_id=identifier, # type: ignore[arg-type]
protocol=protocol,
clean_session=clean_session,
transport=transport,
Expand Down Expand Up @@ -400,7 +400,7 @@ async def unsubscribe(
**kwargs: Additional keyword arguments to pass to paho-mqtt's unsubscribe
method.
"""
result, mid = self._client.unsubscribe(topic, properties, *args, **kwargs)
result, mid = self._client.unsubscribe(topic, properties, *args, **kwargs) # type: ignore[arg-type]
# Early out on error
if result != mqtt.MQTT_ERR_SUCCESS or mid is None:
raise MqttCodeError(result, "Could not unsubscribe from topic")
Expand Down
2 changes: 1 addition & 1 deletion aiomqtt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __str__(self) -> str:
if isinstance(self.rc, ReasonCode):
return f"[code:{self.rc.value}] {self.rc!s}"
if isinstance(self.rc, int):
return f"[code:{self.rc}] {mqtt.error_string(self.rc)}"
return f"[code:{self.rc}] {mqtt.error_string(self.rc)}" # type: ignore[arg-type]
return f"[code:{self.rc}] {super().__str__()}"


Expand Down
16 changes: 6 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [

[tool.poetry.dependencies]
python = "^3.8"
paho-mqtt = {git = "https://github.com/JonathanPlasse/paho.mqtt.python.git", rev = "fix-type-annotations"}
paho-mqtt = "^2.0.0"
typing-extensions = {version = "^4.4.0", markers = "python_version < '3.10'"}

[tool.poetry.group.dev]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def unsubscribe(
) -> tuple[MQTTErrorCode, int | None]:
assert client._outgoing_calls_sem is not None
assert client._outgoing_calls_sem.locked()
return super().unsubscribe(topic, properties)
return super().unsubscribe(topic, properties) # type: ignore[arg-type]

def publish( # noqa: PLR0913
self,
Expand Down
8 changes: 4 additions & 4 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
],
)
def test_mqtt_code_error_int(rc: int) -> None:
assert str(MqttCodeError(rc)) == f"[code:{rc}] {mqtt.error_string(rc)}"
assert str(MqttCodeError(rc)) == f"[code:{rc}] {mqtt.error_string(rc)}" # type: ignore[arg-type]


@pytest.mark.parametrize(
Expand All @@ -42,7 +42,7 @@ def test_mqtt_code_error_int(rc: int) -> None:
],
)
def test_mqtt_code_error_reason_codes(packet_type: int, a_name: str) -> None:
rc = ReasonCode(packet_type, a_name)
rc = ReasonCode(packet_type, a_name) # type: ignore[no-untyped-call]
assert str(MqttCodeError(rc)) == f"[code:{rc.value}] {rc!s}"


Expand All @@ -57,7 +57,7 @@ def test_mqtt_connect_error_int(rc: int, message: str) -> None:
if rc in _CONNECT_RC_STRINGS:
arg += f": {message}"
assert error.args[0] == arg
assert str(error) == f"[code:{rc}] {mqtt.error_string(rc)}"
assert str(error) == f"[code:{rc}] {mqtt.error_string(rc)}" # type: ignore[arg-type]


@pytest.mark.parametrize(
Expand All @@ -69,5 +69,5 @@ def test_mqtt_connect_error_int(rc: int, message: str) -> None:
],
)
def test_mqtt_connect_error_reason_codes(packet_type: int, a_name: str) -> None:
rc = ReasonCode(packet_type, a_name)
rc = ReasonCode(packet_type, a_name) # type: ignore[no-untyped-call]
assert str(MqttConnectError(rc)) == f"[code:{rc.value}] {rc!s}"

0 comments on commit 8321217

Please sign in to comment.