Repository navigation
Conversation
…eading-index paths Closes github#5073. After the Lark grammar landed in github#5171, three expression-evaluator gaps from github#5073 remained on main: - Integer-mantissa exponent literals (such as 1e3, 1E3, -2e+3, 5e-2) were rejected by the NUMBER terminal and _BuildAst.number, even though decimal exponents like 1.5e3 were accepted. - _coerce_number only tried float() when a string contained ".", so exponent-form numeric strings like "1e3" silently failed to coerce in ordering and equality comparisons (evaluating "1e3" > 100 to False while WorkflowEngine._coerce_input coerces "1e3" to 1000). Coercing via int() first and finite float() for digit-bearing strings aligns expression comparisons with workflow input coercion while keeping non-finite strings ("inf", "nan", overflow) as plain strings. - _INDEXED_SEGMENT matched only one [index] suffix, rejecting chained list indexing such as steps.plan.output.matrix[0][1] and item[0][1]. Widening _INDEXED_SEGMENT and walking each bracketed index in _resolve_dot_path propagates automatically to the Lark PATH terminal and condition diagnostics. - The first-segment PATH regex did not apply its leading-digit/hyphen and reserved-word guards to the indexed branch, allowing 1[0], and[0], and not[0] to silently resolve as missing paths (None) instead of raising a syntax error (or, for not[0], negating the list literal [0]). Assisted-by: Antigravity (model: Gemini 4 Neon (XHigh), autonomous)
There was a problem hiding this comment.
🟡 Changes recommended
The numeric fallback can silently round integer strings exceeding Python’s digit limit, producing incorrect comparisons; it needs restriction to decimal or exponent spellings and a conversion-limit regression test.
1 open issue
What changed in this PR
This PR addresses the remaining expression-evaluator gaps from #5073 after the Lark parser migration, extending numeric and indexing support in workflow expressions.
Changes:
- Accepts integer-mantissa exponent literals and finite exponent-form numeric strings in comparisons.
- Supports chained list indexing and rejects invalid first-segment paths.
- Adds regression coverage for valid expressions, malformed syntax, and unresolved indices.
| File | Description |
|---|---|
tests/unit/test_condition_expression_block.py |
Updates diagnostic expectations for exponents and chained indexing. |
tests/test_workflows.py |
Adds numeric coercion, indexing, and invalid-syntax regression cases. |
src/specify_cli/workflows/expressions/operators.py |
Adds finite floating-point fallback for numeric strings. |
src/specify_cli/workflows/expressions/namespace.py |
Resolves multiple list indices within a path segment. |
src/specify_cli/workflows/expressions/engine.py |
Extends exponent parsing and guards indexed root paths. |
Review effort: Balanced (adaptive)
When an integer string exceeds Python's configured int-to-str digit limit, int() raises ValueError. Restrict the float() fallback to strings containing '.', 'e', or 'E' so overlong integer strings remain unchanged instead of silently rounding through float() during comparisons. Add a conversion-limit regression test covering _coerce_number and evaluate_condition. Assisted-by: Antigravity (model: Gemini 4 Neon (High), autonomous)
|
Addressed the Copilot review finding on
Verification on
AI disclosure: Posted on behalf of @yxshee by Antigravity (model: Gemini 4 Neon (High), autonomous mode). The agent authored the fix in |
There was a problem hiding this comment.
🔵 Needs a closer look
Interacting changes to tokenization, numeric coercion, namespace indexing, and diagnostics affect workflow branching and interpolation, requiring broader review than limited-scope automated approval.
No open issues 🎉
1 resolved since last review
Review effort: Balanced (adaptive)
There was a problem hiding this comment.
🔵 Needs a closer look
Cross-cutting changes to tokenization, path resolution, diagnostics, and numeric coercion affect workflow branch and loop decisions, exceeding the limited contract-preserving review scope.
No open issues 🎉
Review effort: Balanced
|
The exponent-literal support looks good. Before merging, please keep the newly supported behavior aligned with Python rather than extending existing differences:
This concerns behavior introduced by this PR; unrelated existing differences can be addressed separately. AI disclosure: Drafted for @mnriem using GitHub Copilot (GPT-6.1 Sol), interactively, based on automated code review and testing. The analysis and wording are AI-generated. |

Description
Closes #5073.
After the Lark grammar landed in #5171 (resolving escaped-quote syntax rejection and unspaced word operators), three expression-evaluator gaps from #5073 remained on
main:engine.py):NUMBERonly attached the optional exponent suffix to decimal numbers (1.5e3), rejecting integer-mantissa exponents like1e3,1E3,-2e+3, and5e-2, and_BuildAst.numberonly calledfloat()when"."was present. Moving the optional(?:[eE][+-]?\d(?:_?\d)*)?suffix outside the decimal/integer alternation and convertinge/Eliterals viafloat()makes{{ 1e3 }}evaluate to1000.0while keeping malformed forms (1e,1e+,1e3.5,1_e3) rejected asValueError.operators.py):_coerce_numberonly calledfloat()when"."appeared in the string, so exponent-form strings like"1e3"fell through as plain strings and silently caused{{ inputs.s > 100 }}and{{ inputs.s == 1000 }}to returnFalse— disagreeing withWorkflowEngine._coerce_input("x", "1e3", {"type": "number"}) == 1000._coerce_numbernow triesint()first (preserving arbitrary-precision integers) and falls back to finitefloat()only for digit-bearing strings, so"1e3"coerces to1000.0while non-finite strings ("inf","-inf","Infinity","nan","1e400") remain plain strings.namespace.py,engine.py):_INDEXED_SEGMENTpreviously accepted only a single[index], rejecting{{ steps.plan.output.matrix[0][1] }}and{{ item[0][1] }}. Widening_INDEXED_SEGMENTto^([\w-]+)((?:\[-?\d+\])+)$and iterating each bracketed index in_resolve_dot_pathpropagates automatically to both the LarkPATHterminal and condition diagnostics. Applying the first-segment leading-digit/hyphen and reserved-word guards to the indexed branch as well prevents1[0]andand[0]from silently lexing as paths returningNone(raisingValueErrorinstead), and letsnot[0]negate the list literal[0](False).Testing
Reproduction and regression evidence on macOS arm64, Python 3.14.6:
Before (
upstream/main): Running the issue [Bug]: Unsupported expression syntax evaluates to None silently instead of raising #5073 reproduction script gave{{ 1e3 }}->ValueError,{{ inputs.n < 1e3 }}->ValueError,{{ inputs.s > 100 }}(withs = "1e3") ->False,{{ steps.plan.output.matrix[0][1] }}->ValueError;{{ 1[0] }},{{ and[0] }}, and{{ not[0] }}silently evaluated toNone. The new regression tests intests/test_workflows.pyandtests/unit/test_condition_expression_block.pyfailed onupstream/main.After (
feb936f): The [Bug]: Unsupported expression syntax evaluates to None silently instead of raising #5073 reproduction script evaluates{{ 1e3 }}->1000.0,{{ inputs.n < 1e3 }}->True,{{ inputs.s > 100 }}->True,{{ steps.plan.output.matrix[0][1] }}->'b', unspaced word operators ->True, and escaped quotes ('it\'s') ->ValueError..venv/bin/specify --help: passPATH="$PWD/.venv/bin:$PATH" LC_ALL=en_US.UTF-8 COLUMNS=1000 .venv/bin/python -m pytest -n auto tests/unit/test_condition_expression_block.py tests/specify_cli/workflows tests/workflows tests/test_workflows.py -q: 3,770 passed, 29 skipped..venv/bin/python .github/scripts/check_file_helper_migration.py --base upstream/main --head HEAD: passuvx ruff@0.15.0 check src testsandgit diff --check upstream/main HEAD: passTested locally with
.venv/bin/specify --help(Windows PowerShell:.\.venv\Scripts\specify.exe --help)Ran relevant existing tests with
.venv/bin/python -m pytest tests -q(Windows PowerShell:.\.venv\Scripts\python.exe -m pytest tests -q); use affected test paths for focused checks andLC_ALL=en_US.UTF-8on macOSTested with a sample project (if applicable)
AI Disclosure
AI disclosure: Authored on behalf of @yxshee using Antigravity (model: Gemini 4 Neon (XHigh), autonomous mode). The agent investigated #5073 against the Lark expression evaluator on
main, wrote the fixes and regression tests infeb936f, ran the verification commands listed above, and drafted this PR description. The commit carries a matchingAssisted-by:trailer.