Skip to content
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

0.27.0: replacing app=app with transport=ASGITransport(app) doesn't type check #3111

Closed
tamird opened this issue Feb 22, 2024 · 0 comments · Fixed by #3109
Closed

0.27.0: replacing app=app with transport=ASGITransport(app) doesn't type check #3111

tamird opened this issue Feb 22, 2024 · 0 comments · Fixed by #3109

Comments

@tamird
Copy link

tamird commented Feb 22, 2024

 @pytest_asyncio.fixture
 async def deprecated_client(deprecated_db_manager: MainDbManager) -> AsyncGenerator[AsyncClient, None]:
     async with _make_mocked_test_app(db_manager=deprecated_db_manager, authorization=False) as app:
-        async with AsyncClient(app=app, base_url=URL, headers=USER_AGENT) as ac:
+        async with AsyncClient(transport=ASGITransport(app), base_url=URL, headers=USER_AGENT) as ac:
             yield ac
% poetry run mypy .                                              
tests/conftest.py:64: error: Argument 1 to "ASGITransport" has incompatible type "FastAPI"; expected "Callable[[dict[str, Any], Callable[[], Awaitable[dict[str, Any]]], Callable[[dict[str, Any]], Coroutine[None, None, None]]], Coroutine[None, None, None]]"  [arg-type]
tests/conftest.py:64: note: "FastAPI.__call__" has type "Callable[[Arg(MutableMapping[str, Any], 'scope'), Arg(Callable[[], Awaitable[MutableMapping[str, Any]]], 'receive'), Arg(Callable[[MutableMapping[str, Any]], Awaitable[None]], 'send')], Coroutine[Any, Any, None]]"
Found 1 error in 1 file (checked 472 source files)
 
 It looks like FastAPI and httpx disagree on the shape of an ASGI application. How am I meant to resolve this?
marcinsulikowski added a commit to marcinsulikowski/fastapi that referenced this issue Aug 28, 2024
The code sample in `docs_src/async_tests/test_main.py` triggers the
following deprecation warning with recent versions of `httpx`:

    DeprecationWarning: The 'app' shortcut is now deprecated.
    Use the explicit style 'transport=ASGITransport(app=...)' instead.

We fix it as suggested by the warning.

Note that due to encode/httpx#3111 the new way
of creating `AsyncClient` passes type checks only when using httpx
version 0.27.2 or newer. This is not a problem for FastAPI itself though
because it does not type check code samples.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant