-
Notifications
You must be signed in to change notification settings - Fork 290
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: reorganize message handling for better type safety and clarity #239
base: main
Are you sure you want to change the base?
Conversation
Move memory stream type definitions to models.py and use them throughout the codebase for better type safety and maintainability. GitHub-Issue:#201
Updates test files to work with the ParsedMessage stream type aliases and fixes a line length issue in test_201_client_hangs_on_logging.py. Github-Issue:#201
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
…ation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
2e3388b
to
0d651d5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple minor observations inline but LGTM!
@@ -22,10 +22,10 @@ | |||
@pytest.mark.anyio | |||
async def test_client_session_initialize(): | |||
client_to_server_send, client_to_server_receive = anyio.create_memory_object_stream[ | |||
JSONRPCMessage | |||
MessageFrame[None] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be MessageFrame[NoneType]
?
RawT = TypeVar("RawT") | ||
|
||
|
||
class MessageFrame(BaseModel, Generic[RawT]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know how fastidious we are about this in general, but fwiw the other classes here are docstringed up pretty thoroughly (and the point of raw
in particular might be worth noting here)
|
||
class MessageFrame(BaseModel, Generic[RawT]): | ||
root: JSONRPCMessage | ||
raw: RawT | None = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like all the uses of MessageFrame
pass raw=None
explicitly - personally seems nice to require that but maybe there are ergo concerns I'm not thinking of? (Minor side benefit to removing the default would be avoiding the usual union-vs-sum confusion when RawT = T | None
...)
Summary
Test plan
GitHub-Issue:#201