Skip to content

Pyright reports false positive error with async streams #1829

Discussion options

You must be logged in to vote

I am fairly certain that this issue can be solved by changing how httpx/_compat.py imports the async context manager

Okay, I'm curious... why might that satisfy pyright's type checking, where the try... except ImportError ... style would not?

# `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 # noqa

If you're able to verify that assumption then I guess we could consider if it's worth switch our style for conditional imports.

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@tomchristie
Comment options

@HarrySky
Comment options

@tomchristie
Comment options

@HarrySky
Comment options

@RobertCraigie
Comment options

Answer selected by RobertCraigie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants