-
Notifications
You must be signed in to change notification settings - Fork 946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make client type annotations compatible with async client usage #1842
Conversation
That is often a fluke, I have restarted it. |
Thanks for trying this; I had gotten stuck earlier. The use of type However, I'm not sure this is the right approach. The key is having the right type signatures below. (They're currently unchecked because they have no types at all). Perhaps you understand how to do it better than my attempts. https://github.com/pymodbus-dev/pymodbus/blob/dev/pymodbus/client/base.py#L168-L212 |
#@alexrudd2 I highly disagree with you, we will maintain duplicated code just to please mypy, especially not when we have a valid alternative. You can find the same approach in many standard libraries. This is totally legal and not against any PEP. Remark the function just passed the future it does not create it. The future is created in a method properly marked with async. |
@jvelo thanks for the PR, to me it an excellent compromise, it does not cause duplicate code, it violates no PEP and it silences mypy. "async' is demanded for functions that use asyncio functionality. |
There's still one aspect we might have overlooked: verification of synchronous code where previously code that would expect |
I confirm that the change I've proposed is not such an improvement over the status quo, since now both sync and async clients cannot make assumption over which side of the union will be returned :/ Sorry to have rushed this, I though it would be simpler than it is. |
Yes, you've articulated the problem I wasn't able to express well :) |
It does not silence |
I suspect we end up writing a generator that generates all functions as sync/async, that is a solution acceptable because it still have a low maintenance point. Basically it could be done with "sed" search for "def" and change to "async def", however the problem is to automate this, |
Ideally it should be possible to write one wrapper (decorator perhaps?) instead of changing all functions. I tried earlier but could not figure it out. |
As per #1821 (comment)