sbtinstruments / aiomqtt

The idiomatic asyncio MQTT client, wrapped around paho-mqtt
https://sbtinstruments.github.io/aiomqtt
BSD 3-Clause "New" or "Revised" License
393 stars 71 forks source link

fix: some type hint #211

Closed vvanglro closed 1 year ago

vvanglro commented 1 year ago

better type hints.

vvanglro commented 1 year ago

I found in the latest pycharm that there is this wrong type hint:

image

While I'm investigating it turns out this is a problem with pycharm. pycharm issue1 pycharm issue2

This is not very friendly for pycharm users, so I wonder if we can do some patch to make the prompt more friendly before pycharm fixes support, or not doing it. like using:

@overload
async def subscribe(
        self,
        topic: SubscribeTopic,
        qos: int = 0,
        options: mqtt.SubscribeOptions | None = None,
        properties: Properties | None = None,
        *args: Any,
        timeout: int = 10,
        **kwargs: Any,
    ) -> tuple[int] | list[mqtt.ReasonCodes]:
vvanglro commented 1 year ago

Yes, derived classes of Client are supported.

frederikaalund commented 1 year ago

LGTM! Cheers. :) Thank you for your contribution to asyncio-mqtt. :+1:

Regarding the pycharm issue: I'm open to workarounds. Your @overload-based workaround is a bit too much for me (defeats the DRY principle). Any other suggestions? :)

JonathanPlasse commented 1 year ago

Great PR! Thanks