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. |
…nd document expression syntax Addresses maintainer review feedback on github#5523: - Revert implicit exponent-string coercion in operators.py so "1e3" stays a string during comparisons while exponent numeric literals like 1e3 evaluate as float. - Raise IndexError on out-of-range chained list indices and TypeError on non-list chained indexing targets instead of silently returning None. - Document exponent literals and chained indexing (including expected errors) in docs/workflows/expressions.md and expand positive and expected-error tests. Assisted-by: Antigravity (model: Gemini 4 Neon (XHigh), autonomous)
|
Addressed the review feedback in
Also updated the PR description to match the final diff. Verification on
AI disclosure: Posted on behalf of @yxshee by Antigravity (model: Gemini 4 Neon (XHigh), autonomous mode). The agent authored the code, documentation, and test updates in |
There was a problem hiding this comment.
🟡 Changes recommended
The documentation incorrectly claims exponent strings are not coerced, although decimal-mantissa forms still undergo float() conversion, misleading workflow authors about comparison semantics.
1 open issue
Review effort: Balanced
Addresses Copilot review feedback on github#5523 (discussion_r4701012470): - Distinguish integer-mantissa exponent strings without a decimal point (such as "1e3", which are not coerced during comparisons) from decimal-mantissa exponent strings containing "." (such as "1.0e3" or "1.5e3", which retain existing float() coercion in operators._coerce_number). - Add clarifying assertions in test_workflows.py covering both forms while leaving operators.py unchanged relative to main. Assisted-by: Antigravity (model: Gemini 4 Neon (XHigh), autonomous)
|
Addressed the Copilot documentation accuracy comment (
Verification on
AI disclosure: Posted on behalf of @yxshee by Antigravity (model: Gemini 4 Neon (XHigh), autonomous mode). The agent authored the documentation and test clarification in |
There was a problem hiding this comment.
🔵 Needs a closer look
The change couples expression tokenization, namespace resolution, and condition handling with runtime exceptions that affect workflow branching, requiring human review of chained-index failure semantics and compatibility.
No open issues 🎉
1 resolved since last review
Review effort: Balanced


Description
Closes #5073.
After the Lark grammar landed in #5171 (resolving escaped-quote syntax rejection and unspaced word operators), two expression-evaluator syntax gaps from #5073 remained on
main:src/specify_cli/workflows/expressions/engine.py):NUMBERpreviously attached the optional exponent suffix only to decimal numbers (1.5e3), rejecting integer-mantissa exponents such as1e3,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 rejecting malformed forms (1e,1e+,1e3.5,1_e3) asValueError. String comparison semantics inoperators.pyare unchanged: integer-mantissa exponent strings without a decimal point (such as"1e3") remain strings during comparisons ("1e3" == 1000and"1e3" == 1e3remainFalse), while decimal-mantissa exponent strings containing.(such as"1.0e3"or"1.5e3") keep existingfloat()coercion inoperators._coerce_number.src/specify_cli/workflows/expressions/namespace.py,src/specify_cli/workflows/expressions/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. Valid chained access (including negative indices such asmatrix[-1][-2]) resolves to the target element, while invalid chained access raisesIndexError(out-of-range index) orTypeError(non-list target) instead of silently returningNone. Applying the first-segment leading-digit/hyphen and reserved-word guards to the indexed branch also prevents1[0]andand[0]from silently lexing as paths returningNone(raisingValueErrorinstead), and letsnot[0]negate the list literal[0](False).docs/workflows/expressions.md): Documented exponent literals (distinguishing comparison semantics for integer-mantissa vs. decimal-mantissa exponent strings), chained/negative list indexing, and their expected errors (ValueError,IndexError,TypeError).Testing
Verification on
2048e217(macOS arm64, Python 3.14.6):PATH="$PWD/.venv/bin:$PATH" LC_ALL=en_US.UTF-8 COLUMNS=1000 .venv/bin/python -m pytest -n auto tests/test_workflows.py tests/unit/test_condition_expression_block.py tests/specify_cli/workflows tests/workflows -q: 3,776 passed, 29 skippeduvx ruff@0.15.0 check src tests: passed.venv/bin/python .github/scripts/check_file_helper_migration.py --base $(git merge-base upstream/main HEAD) --head HEAD: passednpx markdownlint-cli2 docs/workflows/expressions.md: 0 issuesgit diff --check $(git merge-base upstream/main HEAD)..HEAD: passedAI Disclosure
Implemented and updated on behalf of @yxshee using Antigravity (model: Gemini 4 Neon (XHigh), autonomous mode; commit
774012ffused Gemini 4 Neon (High), autonomous mode). AI assistance covered code, documentation, test authoring, verification execution, and PR description drafting.