fix: correct falsy-value handling in list utility helpers#2127
Open
rishi-jat wants to merge 3 commits intooscal-compass:developfrom
Open
fix: correct falsy-value handling in list utility helpers#2127rishi-jat wants to merge 3 commits intooscal-compass:developfrom
rishi-jat wants to merge 3 commits intooscal-compass:developfrom
Conversation
Signed-off-by: Rishi Jat <rishijat098@gmail.com>
Contributor
Author
|
/cc @degenaro |
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect handling of falsy values in dictionary helpers so that valid values like 0, False, and '' are not treated as “missing” and removed.
Changes:
- Update
deep_setto usevalue is not None(instead of truthiness) when deciding whether to set vs. pop. - Update
set_or_popto usevalue is not None(instead of truthiness) when deciding whether to set vs. pop.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
trestle/common/list_utils.py
Outdated
Comment on lines
147
to
150
| if value is not None or not pop_if_none: | ||
| dic[path[-1]] = value | ||
| else: | ||
| dic.pop(path[-1], None) |
There was a problem hiding this comment.
Tests cover deep_set for None, but not for newly supported falsy values (e.g., 0, False, '') nor for set_or_pop semantics. Adding assertions for these cases would prevent regressions and clarify the intended behavior for falsy values vs. empty containers.
Suggested change
| if value is not None or not pop_if_none: | |
| dic[path[-1]] = value | |
| else: | |
| dic.pop(path[-1], None) | |
| if pop_if_none: | |
| set_or_pop(dic, path[-1], value) | |
| else: | |
| dic[path[-1]] = value |
Signed-off-by: Rishi Jat <rishijat098@gmail.com>
7b0abe5 to
641d6cd
Compare
Contributor
Author
|
@vikas-agarwal76 please have a look. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix incorrect handling of falsy values in
deep_setandset_or_popintrestle/common/list_utils.py.Issue
Both functions used truthiness checks (
if value) which caused valid falsy values such as0,False, empty strings, and empty collections to be treated as missing and removed from dictionaries.Changes Made
value is not Nonecomparisons.deep_setset_or_popTests
Added tests to ensure falsy values are preserved while
Nonestill removes keys.