Conversation
Summary of ChangesHello, 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 introduces support for Python's context manager protocol to both the asynchronous Highlights
Changelog
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request implements the context manager protocol for Client and BlockingClient. My review focuses on improving the Python type hints for correctness and consistency, and on the Rust implementation details. I've identified several areas where type hints can be more specific, which improves code clarity and helps static analysis tools. Additionally, the __exit__ methods are currently placeholders, which I've noted. I also suggest a minor code organization improvement in the Rust code.
| async def __aenter__(self) -> Any: ... | ||
| async def __aexit__( | ||
| self, _exc_type: Any, _exc_value: Any, _traceback: Any | ||
| ) -> Any: ... |
There was a problem hiding this comment.
The type hints for __aenter__ and __aexit__ can be more specific. __aenter__ should return an instance of the class, so its return type should be "Client". The __aexit__ method in the Rust implementation doesn't return a value, which corresponds to None in Python.
| async def __aenter__(self) -> Any: ... | |
| async def __aexit__( | |
| self, _exc_type: Any, _exc_value: Any, _traceback: Any | |
| ) -> Any: ... | |
| async def __aenter__(self) -> "Client": ... | |
| async def __aexit__( | |
| self, _exc_type: Any, _exc_value: Any, _traceback: Any | |
| ) -> None: ... |
| """ | ||
|
|
||
| def __enter__(self) -> "Response": ... | ||
| def __enter__(self) -> Any: ... |
There was a problem hiding this comment.
The return type of __enter__ was changed from "Response" to Any. This is a regression in type hint specificity. The __enter__ method should return self, so the type hint should be "Response". Please revert this change.
| def __enter__(self) -> Any: ... | |
| def __enter__(self) -> "Response": ... |
| """ | ||
|
|
||
| def __enter__(self) -> "WebSocket": ... | ||
| def __enter__(self) -> Any: ... |
There was a problem hiding this comment.
The return type of __enter__ was changed from "WebSocket" to Any. This is a regression in type hint specificity. The __enter__ method should return self, so the type hint should be "WebSocket". Please revert this change.
| def __enter__(self) -> Any: ... | |
| def __enter__(self) -> "WebSocket": ... |
| """ | ||
| ... | ||
|
|
||
| def __enter__(self) -> Any: ... |
There was a problem hiding this comment.
| async fn __aexit__(&self, _exc_type: Py<PyAny>, _exc_val: Py<PyAny>, _traceback: Py<PyAny>) { | ||
| // TODO: Implement connection closing logic if necessary. | ||
| } |
There was a problem hiding this comment.
| #[pymethods] | ||
| impl Client { | ||
| #[inline] | ||
| async fn __aenter__(slf: Py<Self>) -> PyResult<Py<Self>> { | ||
| Ok(slf) | ||
| } | ||
|
|
||
| #[inline] | ||
| async fn __aexit__(&self, _exc_type: Py<PyAny>, _exc_val: Py<PyAny>, _traceback: Py<PyAny>) { | ||
| // TODO: Implement connection closing logic if necessary. | ||
| } | ||
| } |
| fn __exit__<'py>( | ||
| &self, | ||
| _py: Python<'py>, | ||
| _exc_type: &Bound<'py, PyAny>, | ||
| _exc_value: &Bound<'py, PyAny>, | ||
| _traceback: &Bound<'py, PyAny>, | ||
| ) { | ||
| // TODO: Implement connection closing logic if necessary. | ||
| } |
| #[pymethods] | ||
| impl BlockingClient { | ||
| #[inline] | ||
| fn __enter__(slf: PyRef<Self>) -> PyRef<Self> { | ||
| slf | ||
| } | ||
|
|
||
| #[inline] | ||
| fn __exit__<'py>( | ||
| &self, | ||
| _py: Python<'py>, | ||
| _exc_type: &Bound<'py, PyAny>, | ||
| _exc_value: &Bound<'py, PyAny>, | ||
| _traceback: &Bound<'py, PyAny>, | ||
| ) { | ||
| // TODO: Implement connection closing logic if necessary. | ||
| } | ||
| } |
No description provided.