Closed jbouwh closed 1 month ago
This is annoying but resolving it would require a breaking change; as such I'm going to tag it as an enhancement.
True, may be we should deprecation the old form and come with a new API that will replace the old one, so they can run some time together.
Closing this as the V2 API made the calls consistent.
One note though. The type stubs seem not updated yet. So mypy will complain about incorrect typing or the absence of CallbackAPIVersion
, this should be fixed too before we can upgrade to 2.1.0.
@jbouwh (working way outside my knowledge level here :-) ) - I believe the type info is all there:
CallbackOnSubscribe_v1_mqtt3 = Callable[["Client", Any, int, Tuple[int, ...]], None]
CallbackOnSubscribe_v1_mqtt5 = Callable[["Client", Any, int, List[ReasonCode], Properties], None]
CallbackOnSubscribe_v1 = Union[CallbackOnSubscribe_v1_mqtt3, CallbackOnSubscribe_v1_mqtt5]
CallbackOnSubscribe_v2 = Callable[["Client", Any, int, List[ReasonCode], Union[Properties, None]], None]
CallbackOnSubscribe = Union[CallbackOnSubscribe_v1, CallbackOnSubscribe_v2]
but it's pretty complicated due to the multiple API versions. Might be worth raising a seperate issue with full details (but I don't know if this may be a limitation with the tool, intellij seems to pickup the type info OK and lists a multitude of possibilities).
@jbouwh (working way outside my knowledge level here :-) ) - I believe the type info is all there:
CallbackOnSubscribe_v1_mqtt3 = Callable[["Client", Any, int, Tuple[int, ...]], None] CallbackOnSubscribe_v1_mqtt5 = Callable[["Client", Any, int, List[ReasonCode], Properties], None] CallbackOnSubscribe_v1 = Union[CallbackOnSubscribe_v1_mqtt3, CallbackOnSubscribe_v1_mqtt5] CallbackOnSubscribe_v2 = Callable[["Client", Any, int, List[ReasonCode], Union[Properties, None]], None] CallbackOnSubscribe = Union[CallbackOnSubscribe_v1, CallbackOnSubscribe_v2]
but it's pretty complicated due to the multiple API versions. Might be worth raising a seperate issue with full details (but I don't know if this may be a limitation with the tool, intellij seems to pickup the type info OK and lists a multitude of possibilities). Right, the code works btw, it is just the type stubs, imo multiple existing issues have the same root cause.
The MQTT v5 callback parameters for
reasoncodes
andproperties
are swapped foron_subscribe()
andon_unsubscribe()
. This is very confusing and makes it harder to reuse the callback handler.on_subscribe(self, self._userdata, mid, reasoncodes, properties)
https://github.com/eclipse/paho.mqtt.python/blob/9782ab81fe7ee3a05e74c7f3e1d03d5611ea4be4/src/paho/mqtt/client.py#L3258-L3259
on_unsubscribe(self, self._userdata, mid, properties, reasoncodes)
https://github.com/eclipse/paho.mqtt.python/blob/9782ab81fe7ee3a05e74c7f3e1d03d5611ea4be4/src/paho/mqtt/client.py#L3452-L3453