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

♻️ Use asgiref typing instead of starlette types #1206

Closed
wants to merge 1 commit into from

Conversation

Kludex
Copy link
Member

@Kludex Kludex commented Jun 20, 2021

Since uvicorn added asgiref as a dependency (for typing), we probably want to do the same here.

I didn't discuss this yet, so I'm not sure about the opinion of other members, feel free to comment if you see this. I'm going to write more about this later on.

@JayH5
Copy link
Member

JayH5 commented Jun 22, 2021

Not against this eventually as it'd be nice to have shared types between encode projects. However, a first step might be to just re-export the asgiref types as the ones we use under starlette.types. That would greatly reduce the changes and make it a lot easier for our users to upgrade.

@Kludex
Copy link
Member Author

Kludex commented Jun 22, 2021

However, a first step might be to just re-export the asgiref types as the ones we use under starlette.types.

I thought about that, but I think the Message will be an issue, as there's no compatibility with asgiref. Message would be something like Union[ASGIReceiveEvent, ASGISendEvent], but this will probably cause a lot of mypy conflicts.

That being said, I'm going to try your suggestion in a few days. 👍

@Kludex
Copy link
Member Author

Kludex commented Jun 25, 2021

Ok. I tried that.

import typing

from asgiref.typing import Scope  # noqa: F401
from asgiref.typing import (
    ASGI3Application,
    ASGIReceiveCallable,
    ASGIReceiveEvent,
    ASGISendCallable,
    ASGISendEvent,
)

Message = typing.Union[ASGIReceiveEvent, ASGISendEvent]

Receive = ASGIReceiveCallable
Send = ASGISendCallable

ASGIApp = ASGI3Application

And I got:

Found 518 errors in 19 files (checked 62 source files)

😆 🤣

@Kludex
Copy link
Member Author

Kludex commented Jun 25, 2021

I'll close this because I'll not have time to solve the conflicts here. There are ~280.

If we don't do this, when using uvicorn.run, we'll always have to ignore the mypy error now that uvicorn is almost fully mypy compliant.

@Kludex Kludex closed this Jun 25, 2021
@Kludex Kludex mentioned this pull request Jun 25, 2021
2 tasks
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 this pull request may close these issues.

2 participants