Async for support for websockets
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.7k
- Forks
- 206
- PR merge metrics
- No merged PRs in 30d
Description
Hello @pgjones,
I just would like to keep up this topic.
There was a discussion in which Nathaniel J. Smith mentioned that async for support for websockets would be more pythonic.
Currently:
while True:
result = await websocket.receive_json()
The more idiomatic:
async for result in websocket.receive_json():
...
It would be great that the async for loop supports both receive and receive_json methods.
Thanks for your help in advance.
Best Regards,
András
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue identifies websocket.receive and websocket.receive_json as the relevant entry points; start by tracing their implementation and current websocket iteration behavior. Confirm how async iteration could support both methods, then verify that receiving JSON and non-JSON messages works through the proposed interface.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100