Repository navigation
Reject rule radix below 2 - #18
Merged
Merged
Conversation
The divisor loop looks for the largest power of the radix at or below the rule's value, which never terminates for a radix of 0 or 1. Raise ValueError when such a rule is created instead of hanging later while formatting. Also note PR #17's divisor fix in the changelog. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
RbnfRulenow raisesValueErrorwhen it's created with a radix below 2.Why
Since #17, the divisor is found by multiplying up to the largest power of the radix that is at or below the rule's value. With a radix of 0 or 1 that loop never ends, so a rule added via
add_rule(..., radix=1)would hang the first time it formatted a number (before #17 it raised frommath.log). No bundled CLDR file uses such a radix; this only guards hand-added rules.Notes for review
RbnfRule.__post_init__, so it covers bothadd_ruleand XML loading.RbnfRule.parse, the rule is now constructed outside thetrythat catchesValueErrorfromint(value_str). Otherwise the new error would be swallowed and logged as "Unrecognized special rule".CHANGELOG.md: added this change and the Fix divisor computation: use highest power of radix <= rule value #17 divisor fix (which wasn't listed) under "Unreleased".Testing
test_invalid_radix_is_rejectedcovers radix 0, 1 and -10.pytest: 135 passed.script/lint(black, isort, flake8, pylint, mypy): clean.🤖 Generated with Claude Code