When using async with controller.collect(...) as response, PyCharm fails to understand the AsyncContextManager[Response] type annotation and infers response as Any.
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):
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.
Keep trying to find another workaround that will make PyCharm happy.
Re-architect the @asynccontextmanager design (please no, I find it great 🤦)
When using
async with controller.collect(...) as response
, PyCharm fails to understand theAsyncContextManager[Response]
type annotation and infersresponse
asAny
.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:
collect
in BotControllercollect
incollector
(used by the controller)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):typing.cast
oras response: # type: Response
as workarounds.