Skip to content

Preserve slice projections after array indexes - #374

Closed
Eric3-jp wants to merge 1 commit into
jmespath:developfrom
Eric3-jp:fix/slice-projection-after-index
Closed

Eric3-jp wants to merge 1 commit into
jmespath:developfrom
Eric3-jp:fix/slice-projection-after-index

Conversation

@Eric3-jp

Copy link
Copy Markdown

For data = {'foo': [[{'a': 1}, {'a': 2}]]}, the expression foo[0][:2].a currently returns None instead of [1, 2]. A slice following an array index bypasses projection construction, so subsequent expressions are evaluated against the entire sliced list instead of its elements. foo[0] | [:2].a already produces the expected result, consistent with the documented slice projection behavior.

Exclude slices from the optimization that combines consecutive indexes, allowing them to use the existing _project_if_slice path. Consecutive scalar indexes retain the optimization.

Add 13 compliance cases covering field/root expressions, positive and negative indexes, repeated indexes, reverse and empty slices, missing fields, subsequent array indexes, pipe boundaries, non-array inputs, and null omission. The changelog is updated.

Validation on CPython 3.11.16 under Ubuntu 24.04, using the repository's test dependency versions:

  • Before the parser change, the slice compliance file had 8 failures and 46 passes; all failures were among the new cases.
  • Afterward, python -m pytest tests -q --cov=jmespath --cov-report=term-missing: 1004 passed, 1 skipped, 99% overall coverage.
  • git diff --check: passed.

The full Python/platform CI matrix was not run locally.

Developed with assistance from OpenAI Codex.

@Eric3-jp Eric3-jp closed this by deleting the head repository Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant