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

Starlette is not typed to an ASGIApplication → Type check warning in PyCharm with FastAPI and Uvicorn #1296

Closed
eshfield opened this issue Oct 2, 2021 · 1 comment

Comments

@eshfield
Copy link

eshfield commented Oct 2, 2021

The problem:
PyCharm gives ugly type check warning when I try to run FastAPI app with uvicorn programmatically passing to uvicorn.run() the application instance of the FastAPI class.

I have created the issue in the FastAPI repository and they say the problem is since FastAPI extends from Starlette the issue is that Starlette is not typed to an ASGIApplication, i.e. fix must be done in the Starlette code:
fastapi/fastapi#3927

Steps to reproduce:
Copy and paste to PyCharm the example code from the official FastAPI documentation Debugging → Call uvicorn
PyCharm will highlight the app argument at the last line uvicorn.run(app, host="0.0.0.0", port=8000) with warning:
Expected type 'Union[Type[ASGI2Protocol], (Union[HTTPScope, WebSocketScope, LifespanScope], () -> Awaitable[Union[HTTPRequestEvent, HTTPDisconnectEvent, WebSocketConnectEvent, WebSocketReceiveEvent, WebSocketDisconnectEvent, LifespanStartupEvent, LifespanShutdownEvent]], (Union[HTTPResponseStartEvent, HTTPResponseBodyEvent, HTTPServerPushEvent, HTTPDisconnectEvent, WebSocketAcceptEvent, WebSocketSendEvent, WebSocketResponseStartEvent, WebSocketResponseBodyEvent, WebSocketCloseEvent, LifespanStartupCompleteEvent, LifespanStartupFailedEvent, LifespanShutdownCompleteEvent, LifespanShutdownFailedEvent]) -> Awaitable[None]) -> Awaitable[None], str]', got 'FastAPI' instead

@Kludex
Copy link
Member

Kludex commented Oct 2, 2021

Duplicated #1249

PR is welcome. :)

@Kludex Kludex closed this as completed Oct 2, 2021
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

No branches or pull requests

2 participants