Skip to content

refactor(ws): simplify Message creation#517

Merged
0x676e67 merged 2 commits intomainfrom
ref
Feb 13, 2026
Merged

refactor(ws): simplify Message creation#517
0x676e67 merged 2 commits intomainfrom
ref

Conversation

@0x676e67
Copy link
Copy Markdown
Owner

No description provided.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @0x676e67, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the Message creation process within the ws module to simplify how WebSocket messages are constructed, particularly when dealing with JSON content. It unifies the static creation methods for text and binary messages to accept both raw data and JSON-serializable objects, enhancing API consistency and reducing redundancy.

Highlights

  • Unified Message Creation: The from_text and from_binary static methods in the Python Message class now accept both raw string/bytes and JSON-serializable data, consolidating message creation and removing the need for separate *_from_json methods.
  • JSON Property Access: A new json property has been introduced to the Python Message class, providing a more idiomatic way to access the JSON representation of a message, replacing the previous json() method.
  • Internal Refactoring (Rust): New BytesLike and TextLike enums were added to the Rust implementation to support the unified message creation logic, allowing from_text and from_binary to handle diverse input types. The json method was also converted into a #[getter] property.
Changelog
  • python/rnet/init.pyi
    • Removed text_from_json and binary_from_json static methods.
    • Updated from_text and from_binary static methods to accept str | Any and bytes | Any respectively, allowing direct JSON input.
    • Added a json: Any property to the Message class.
    • Removed the json() instance method type hint.
  • src/client/resp/ws/msg.rs
    • Introduced BytesLike and TextLike enums to encapsulate different input types for message creation.
    • Refactored from_text and from_binary static methods to leverage TextLike and BytesLike for unified handling of raw data and JSON.
    • Converted the json method into a #[getter] property for more Pythonic access.
    • Added Debug trait to std::fmt import.
    • Optimized the fmt::Display implementation with #[inline] and direct forwarding.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the creation of Message objects to simplify the API, which is a good improvement. The approach of using FromPyObject with enums to handle different input types is effective. However, I've identified a critical issue where the code could panic on invalid user input, which should be addressed. I've also found a minor error in the documentation.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Feb 13, 2026

Deploying rnet with  Cloudflare Pages  Cloudflare Pages

Latest commit: d0073ec
Status: ✅  Deploy successful!
Preview URL: https://dec10e49.rnet-7tt.pages.dev
Branch Preview URL: https://ref.rnet-7tt.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant