JosXa / tgintegration

Integration test and automation library for Telegram Messenger bots based on Pyrogram.
https://josxa.github.io/tgintegration/
MIT License
119 stars 18 forks source link

No type inference for Response type in collector when using PyCharm #15

Open JosXa opened 4 years ago

JosXa commented 4 years ago

When using async with controller.collect(...) as response, PyCharm fails to understand the AsyncContextManager[Response] type annotation and infers response as Any.

This is due to a bug in PyCharm itself, which is reported on their YouTrack board (and not planned since two years): https://youtrack.jetbrains.com/issue/PY-29891

If someone wants to look into this, here are the relevant type annotations:

Now, since this is the integral part of tgintegration, we need to find a solution (Update 2020-10-25: # type: Response has been added to all examples):

  1. Leave it as it is, wait for and push JetBrains to fix the bug (I'd need help from the community for that). Add documentation on how to use typing.cast or as response: # type: Response as workarounds.
  2. Keep trying to find another workaround that will make PyCharm happy.
  3. Re-architect the @asynccontextmanager design (please no, I find it great 🤦)
JosXa commented 1 year ago

Seems there is a bugfix in the works: https://youtrack.jetbrains.com/issue/PY-36444/PyCharm-doesnt-infer-types-when-using-contextlib.contextmanager-decorator