fix(core): preserve legitimate falsy values in _clean_empty#713
Conversation
Summary of ChangesHello @cchinchilla-dev, 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 addresses a bug in the Highlights
Changelog
Activity
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
The pull request correctly addresses the issue where falsy but legitimate values (such as 0, False, and 0.0) were being stripped during the cleaning process for agent card canonicalization. The implementation of _clean_empty has been improved to explicitly check for None and handle empty strings at the leaf level, ensuring that other falsy values are preserved. The added tests are comprehensive and include a regression test for the reported issue. The review follows PEP 8 for Python code style.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request correctly fixes an issue in _clean_empty where legitimate falsy values (like 0 or False) were being removed along with empty strings and collections. The new implementation properly distinguishes between these cases. The accompanying tests are very thorough and cover a wide range of scenarios, including a regression test for the original bug. I've kept all the minor suggestions to improve code efficiency and clarity. Overall, this is a high-quality contribution.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
Thanks a lot for pointing this bug out and for opening a PR request! Regarding alternatives considered: I prefer your short-circuit evaluation over the former inline sentinel and currently don't see the need for adding |
🤖 I have created a release *beep* *boop* --- ## [0.3.24](v0.3.23...v0.3.24) (2026-02-20) ### Bug Fixes * **core:** preserve legitimate falsy values in _clean_empty ([#713](#713)) ([7632f55](7632f55)) * **deps:** `DeprecationWarning` on `HTTP_413_REQUEST_ENTITY_TOO_LARGE` ([#693](#693)) ([9968f9c](9968f9c)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Description
Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
CONTRIBUTINGGuide.fix:which represents bug fixes, and correlates to a SemVer patch.feat:represents a new feature, and correlates to a SemVer minor.feat!:, orfix!:,refactor!:, etc., which represent a breaking change (indicated by the!) and will result in a SemVer major.bash scripts/format.shfrom the repository root to format)Fixes #692 🦕
Problem
_clean_emptyuses a truthiness check (if v) that drops legitimate falsy values like0,False, and0.0alongside the intended empties ('',[],{}).This affects
canonicalize_agent_card()— the only caller — which produces canonical JSON for signature verification (RFC 8785). AnAgentCardwith e.g.AgentCapabilities(streaming=False)would have the field silently stripped, losing the distinction between "explicitly disabled" and "unspecified".Fix
Restructured
_clean_emptyso that only empty strings are converted toNoneat the leaf level, and empty containers collapse naturally viaor Noneafter their children are cleaned. The filter becomesif v is not None, which only catches values the function itself converted —0,False, and0.0never go through any conversion and flow through unchanged.Alternatives considered
If maintainers prefer a different style, happy to switch to either:
if v not in (None, '', [], {})directly in the comprehensions, keeping the original structure with a fixed filter._is_empty(v)function and useif not _is_empty(v)as the filter in both dict and list comprehensions.Tests
Parametrized tests covering empty removal, falsy value preservation, mixed cases, non-mutation, and a regression test confirming
streaming=Falsesurvives incanonicalize_agent_cardoutput. Happy to trim test cases if seen as excessive.