Pyright reports false positive error with async streams #1829
Answered
by
lovelydinosaur
RobertCraigie
asked this question in
Potential Issue
-
Problemfrom httpx import AsyncClient
async def main(url: str) -> None:
client = AsyncClient()
async with client.stream('GET', url) as resp:
...Pyright reports: SolutionAlthough I haven't checked, I am fairly certain that this issue can be solved by changing how import sys
# `contextlib.asynccontextmanager` exists from Python 3.7 onwards.
# For 3.6 we require the `async_generator` package for a backported version.
if sys.version_info >= (3, 7):
from contextlib import asynccontextmanager
else:
from async_generator import asynccontextmanager |
Beta Was this translation helpful? Give feedback.
Answered by
lovelydinosaur
Sep 3, 2021
Replies: 1 comment 6 replies
-
Okay, I'm curious... why might that satisfy # `contextlib.asynccontextmanager` exists from Python 3.7 onwards.
# For 3.6 we require the `async_generator` package for a backported version.
try:
from contextlib import asynccontextmanager # type: ignore
except ImportError:
from async_generator import asynccontextmanager # type: ignore # noqaIf you're able to verify that assumption then I guess we could consider if it's worth switch our style for conditional imports. |
Beta Was this translation helpful? Give feedback.
6 replies
Answer selected by
RobertCraigie
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Okay, I'm curious... why might that satisfy
pyright's type checking, where thetry... except ImportError ...style would not?If you're able to verify that assumption then I guess we could consider if it's worth switch our style for conditional imports.