-
Notifications
You must be signed in to change notification settings - Fork 37
fix: remove float_precision for protobuf 7 #559
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
Conversation
Summary of ChangesHello @daniel-sanche, 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 updates the library to gracefully manage the breaking change introduced in Protobuf 7, where the Highlights
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.
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 correctly addresses the removal of the float_precision argument in Protobuf 7. The approach of ignoring the argument and issuing a DeprecationWarning for newer versions is sound. The refactoring of to_json and to_dict into a shared helper function is a good improvement for code maintainability. I have one minor suggestion to simplify the logic for extracting the Protobuf major version.
|
@daniel-sanche , Please could you address the failing tests? |
tests/test_json.py
Outdated
|
|
||
| # TODO: https://github.com/googleapis/proto-plus-python/issues/390 | ||
| def test_json_float_precision(): | ||
| if int(proto.message._PROTOBUF_MAJOR_VERSION) >= 7: |
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.
NO ACTION:
I situations like this, I often choose to decorate a test with @pytest.mark.parametrize() and include one or more happy paths and sad paths (labeled with IDs for clarity when looking at the pytest results) rather than writing two separate tests. Avoids a lot of duplicate code. Not saying you need to do anything here. Just pointing it out as an option for future tests down the road.
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.
Good point. I think they started out different, but the code is pretty similar now. I'll take another look
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.
Approved with suggested fixes for minor spelling and grammar errors.
Also, includes a suggestion for future work, that is not required to be incorporated here (NO ACTION).
proto/message.py
Outdated
| warnings.warn(warning_msg, DeprecationWarning, stacklevel=3) | ||
| # supress similar float_precision warning from protobuf library | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("ignore", category=UserWarning) |
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.
One downside of this approach is that we will no longer see new user warnings. For example, in October 2025, https://pypi.org/project/protobuf/6.33.0/ included a new deprecation warning for the float_precision argument, within the same major version. See the release notes for https://github.com/protocolbuffers/protobuf/releases/tag/v33.0-rc1
Can we use warnings.filterwarnings to narrow down the warnings that are filtered to the one that includes the text float_precision?
warnings.filterwarnings("ignore", message=".*float_precision.*")
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.
good point, fixed
Co-authored-by: Chalmer Lowe <chalmerlowe@google.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
Fixes googleapis/google-cloud-python#15099
Protobuf 7 is removing the float_prevision argument. This PR ignores it when passed in 7.x+, and raises a DeprecationWarning