question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use of asgiref typing

See original GitHub issue

Checklist

  • There are no similar issues or pull requests for this yet.
  • @JayH5 and @Kludex are positive about this idea, but it was not discussed on our Gitter channel.

Is your feature related to a problem? Please describe.

On uvicorn we started a mypy compliance goal since some time ago, and we’re about to accomplish it. On this road, we decided to use asgiref typing to annotate ASGI related types.

What I propose is that we do the same for Starlette.

Describe the solution you would like.

Remove the types.py module, and annotate everything that is needed with asgiref.typing types.

There’s no matching type to Message, as discussed on #1206 . So even if it would be more pleasant to our users, unfortunately it will be more troublesome to follow that path.

Describe alternatives you considered

Use Message as Union[ASGISendCallable, ASGIReceiveCallable] and solve the mypy issues. It will be more pleasant to ours users.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
br3ndonlandcommented, Dec 15, 2021

The problem is that I’m not 100% sure, but I think what makes the issue hard to solve is the Message type. You’ll see the mypy errors if you experiment some changes locally.

That being said… I believe the approach would be:

  1. Split Message into ASGISendEvent and ASGIReceiveEvent - naming matching asgiref.
  2. Rename the other types to asgiref (just renaming, not introduce the package yet).
  3. Remove the types definition and import from asgiref - this should be straightforward based on step 2.

I helped with type-annotating Uvicorn, and I’m happy to help here as well.

I’ve already made some good progress, and I’m on step 3 now. I need to correct a few type errors, now that we’re importing from the more specific asgiref types.

Should have a PR up shortly.

1reaction
Kludexcommented, Dec 15, 2021

@br3ndonland Cool! I’ll be happy to review it.

Just take in consideration that the steps mentioned were also a way to minimize the diff and make the review process easier. 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

asgiref/typing.py at main
asgiref /asgiref/typing.py. Go to file · Go to file T
Read more >
asgiref
ASGI is a standard for Python asynchronous web apps and servers to communicate with each other, and positioned as an asynchronous successor to...
Read more >
How to use the asgiref.sync function in ...
To help you get started, we've selected a few asgiref.sync examples, based on popular ways it is used in public projects.
Read more >
fastapi uvicorn No module named 'asgiref.typing'
... simple fastapi application. Once I want to serve it with uvicron I got this error; ModuleNotFoundError: No module named 'asgiref.typing'.
Read more >
Source code for asgiref.sync
This uses an asgiref # Local, not a threadlocal, so that tasks can work out what their ... __self__ # type: ignore except...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found