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

Replace asgiref for native types #1476

Closed
wants to merge 3 commits into from
Closed

Conversation

Kludex
Copy link
Sponsor Member

@Kludex Kludex commented May 6, 2022

Questions

  • Where should I add the asgiref copyright?

@Kludex Kludex requested a review from a team May 6, 2022 05:13
@Kludex Kludex added the clean up label May 6, 2022
@Kludex Kludex added this to the Version 0.18.0 milestone May 6, 2022
@adriangb
Copy link
Member

adriangb commented May 6, 2022

First off thank you for all of these great PRs. I can tell you're putting a great deal of work into trying out all of the alternatives.

I like the idea of having our own types vs. #1460. Two questions:

  1. Will this break integrations with other packages, e.g. a middleware that uses the asgiref types? Or will it still work as long as they are "equivalent"?
  2. What do you think would be the pros/cons of having simpler types, like we have in Starlette? I think we're mainly using these internally within the codebase, so if it's just for us, do we need the more complex types to catch our mistakes, or would the simpler types be enough?

@Kludex
Copy link
Sponsor Member Author

Kludex commented May 6, 2022

Will this break integrations with other packages, e.g. a middleware that uses the asgiref types? Or will it still work as long as they are "equivalent"?

It will work as long as the types are equivalent.

from typing import Protocol, cast


class AsgirefType(Protocol):
    def __call__(self, a: int) -> None:
        ...


class UvicornType(Protocol):
    def __call__(self, a: int) -> None:
        ...


def uvicorn_code(callable: UvicornType) -> None:
    ...


def lamb(a: int) -> None:
    ...


asgiref_callable = cast(AsgirefType, lamb)
uvicorn_code(asgiref_callable)  # uvicorn_code expects UvicornType, but we are giving AsgirefType

The above works - no issues with mypy or pyright.

What do you think would be the pros/cons of having simpler types, like we have in Starlette? I think we're mainly using these internally within the codebase, so if it's just for us, do we need the more complex types to catch our mistakes, or would the simpler types be enough?

I can see a path from the less strict types to the more strict ones, but I don't see any reason to follow this now.

@Kludex
Copy link
Sponsor Member Author

Kludex commented Jun 20, 2022

@Kludex Kludex closed this Jun 20, 2022
@Kludex Kludex deleted the remove-asgiref-dependency branch October 2, 2022 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

asgiref backward compatibility
2 participants