fix(parse): add parentheses for operator precedence in minItems check#1600
Open
xodn348 wants to merge 1 commit into
Open
fix(parse): add parentheses for operator precedence in minItems check#1600xodn348 wants to merge 1 commit into
xodn348 wants to merge 1 commit into
Conversation
The condition on line 149 of _transform.py evaluated as: (min_items is not None and min_items == 0) or (min_items == 1) instead of the intended: min_items is not None and (min_items == 0 or min_items == 1) While both produce the same result for all practical inputs, the explicit parentheses clarify intent and prevent future misreadings. Adds test coverage for minItems 0 and 1 cases.
|
This looks behavior-preserving rather than a parser fix. The original condition already only keeps If the goal is readability, it may be clearer to frame this as a small cleanup. If there is an actual failing schema case, the regression test should cover a value that fails before this change. |
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.
What
Adds explicit parentheses to the
minItemscondition intransform_schema()to clarify operator precedence, and adds missing test coverage forminItems: 0andminItems: 1.Why
The condition on line 149 of
_transform.py:evaluates as
(min_items is not None and min_items == 0) or (min_items == 1)due to Python's operator precedence (andbinds tighter thanor). The intended grouping ismin_items is not None and (min_items == 0 or min_items == 1).Both produce identical results for all practical inputs (
None,0,1,2+), so this is not a behavioral bug — but the missing parentheses make the intent ambiguous and could mislead future readers or refactors.Changes
src/anthropic/lib/_parse/_transform.py: Add parentheses around theorclausetests/lib/_parse/test_transform.py: Addtest_array_schema_min_items_zeroandtest_array_schema_min_items_oneto cover the previously untested code pathVerification