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

Refactor WSMessage to use tagged unions #7319

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

Dreamsorcerer
Copy link
Member

This reworks WSMessage to be a union of dataclasses which can provide much better type safety using tagged unions (on the type attribute).

I need to go over a couple of details (like what should be exported and from where, imports are a little messy currently). But, my main question before I finish it off, is whether it makes sense to have .json() only on the TEXT/BINARY messages? If we do this, it becomes easy for mypy to validate the code, requiring a msg.type is WSMsgType.TEXT check before calling .json().

Fixes #7313

@Dreamsorcerer Dreamsorcerer added the backport:skip Skip backport bot label Jun 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip Skip backport bot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

websocket: message.json() fails with a TypeError when the message exceeds the size limit
1 participant