Repository navigation
physical-quantities: apply the unit factor to each value of a list - #16
Merged
Merged
Conversation
A value that stands for several values ({1, 2}, a LaTeX comma list such as
1,2~\mathrm{m}, or ±) with a unit was multiplied by the unit factor as a
whole, "((1, 2))*(1)", which raised QuantityParseError. The factor is now
applied to each value. A single value is converted as before (the parity
check is unchanged).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 28, 2026
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
A quantity whose value stands for several values had the unit factor applied to the list as a whole.
sympy_formsbuilt({value})*({factor}), so{1, 2} kmbecame((1, 2))*(1000), andparse_quantityraisedQuantityParseError("A bracketed list such as (a, b) can't be used in arithmetic"). This contradicted the documentedstandard_values("several for a value such as{1, 2}").Affected inputs, each with a unit:
{1, 2} km1,2~\mathrm{km}(a LaTeX comma list)plus_minus 2 km\pm 2~\mathrm{km}When
create_expression_setfinds more than one value, the factor is now applied to each value. A single value is converted exactly as before.Found while porting compareExpressions' main #295 onto the refactor (
test_latex_response_parsed_as_liston compareExpressions #280).Testing
test_unit_factor_applies_to_each_value_of_a_listinphysical_quantities/tests/test_regressions.pywith four cases. All four fail without the fix.scripts/test.sh: slr_parsing 116, criteria 105, expression_parsing 519 and physical_quantities 542, all passing.ruff check,ruff format --checkandmypyare clean.tools/parity/check.pyshows 0 unexpected changes and 0 mismatched. A first attempt multiplied the parsed values for single values too, which changed forms such as3*micro*1to3*micro. Single values therefore keep the text route.Follow-up (compareExpressions)
The app's LaTeX quantity preview (
app/preview/physical_quantity.py) reads the value withparse_expression, so it still raises for a list. It needs to show either both values or the last one (main #295 kept the last one, giving2 metre). That change goes with the pin bump that picks this up.🤖 Generated with Claude Code