Repository navigation
fix(calculator): accept signed values and reject trailing input in conversions - #737
Conversation
chrisknvidia
left a comment
There was a problem hiding this comment.
Thanks, this is a clean fix and I could reproduce all three problems on main: -40 celsius to fahrenheit and -10% of 50 failed with Error: invalid syntax, 10% of 50 + 5 printed Result: 5, and 1.2.3 km to miles died with a ValueError traceback. With this branch they give -40 celsius = -40 fahrenheit, Result: -5, and an Error: line with exit code 1.
I also checked that the documented examples (100 celsius to fahrenheit, 15% of 200, 5 miles to km, plain arithmetic, 5 % 3) print exactly what they did before, that mixed case still works, and that 5., .5 and +5 are accepted by the new number pattern. The grader reference trajectories that record calculator output (Result: 30 for 15% of 200, Result: -5 for 3 - 8) still match the script. The new test file fails 7 of 10 cases against the old script and passes 10 of 10 with the fix. Ruff check and format are clean, every commit is signed off, and the changelog entry is in the right place.
Looks good to me.
|
@chrisknvidia thanks a lot for going through it that carefully, especially checking the grader trajectories. If there's nothing else, would you be able to approve and merge it? |
…ing input Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
f84f3c7 to
abd4b5b
Compare
rng1995
left a comment
There was a problem hiding this comment.
Thanks for your contribution, @dhananjay6561. Reviewed abd4b5b9125d; no new actionable defects found. The signed-decimal pattern and full-string matching handle negative conversions/percentages and reject trailing or malformed input through the normal error path. I checked the documented examples and arithmetic fallback.
Validation: All 10 calculator regression tests passed.
Existing review feedback is positive; I have no additional change requests.
rng1995
left a comment
There was a problem hiding this comment.
Thanks, @dhananjay6561. Rechecked 4cbc364fe93e and the latest discussion. The delta from abd4b5b9125d only merges main's task-list fix (#680), its tests and changelog. Calculator source, its regression tests and dependencies are unchanged; no new actionable defects found.
Retained validation: all 10 calculator regression tests passed on abd4b5b9125d; I did not rerun them for this unrelated merge. Existing review feedback remains positive, and I have no additional change requests.
Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com>
Summary
The calculator reference skill parsed conversions and percentages with
re.match(r"([\d.]+)..."). That rejected negative values (-40 celsius to fahrenheitfailed withError: invalid syntax) and, since the pattern wasn't anchored at the end, quietly ignored anything after a match:10% of 50 + 5printedResult: 5. A malformed number like1.2.3 km to milesmatched and then crashed with aValueErrortraceback.Both patterns now use
re.fullmatchwith a signed decimal number pattern:-40 celsius to fahrenheit→-40 celsius = -40 fahrenheit,-10% of 50→Result: -510% of 50 + 5,5 km to miles pleaseand1.2.3 km to milesare no longer treated as a conversion/percentage, so they get the usualError: ...line and exit code 1 instead of a wrong answer or a traceback100 celsius to fahrenheit,15% of 200,5 miles to km, plain arithmetic) give the same output as beforeFixes #735.
Verification
make lintmake testmake buildTested on macOS 26.6 arm64, Python 3.14.7, on top of upstream
d2cb1388.pytest -n 0 tests/test_reference_calculator.py: 10 passed. Against the unchangedcalc.pythe same file has 7 failures (the four signed-value cases and the three trailing-input cases).ruff check src testsandruff format --checkon the changed files: passed.python -m build: built the sdist and wheel.make testsuite; the change is limited to the standalone calculator script, which nothing else imports.Release Impact
CHANGELOG.md