Skip to content

A dictsort pair reads as the 2-tuple (key, value) (0159) - #492

Merged
rmorozov merged 3 commits into
masterfrom
claude/project-thread-e8sgg7
Oct 12, 2026
Merged

rmorozov merged 3 commits into
masterfrom
claude/project-thread-e8sgg7

Conversation

@rmorozov

Copy link
Copy Markdown
Member

Requested by Ruslan · project thread

Before: {% set p = {'ab': 1}|dictsort|first %}{{ p[0] }}|{{ p[1] }}|{{ p|length }} rendered ||; a dictsort pair (a KeyValuePair) had no subscript by index, no length, and p|list was empty.

After: it renders ab|1|2 as Python does. p[0], p[1], negative indexes (out of range is undefined), iteration, |length, |list, |last and unpacking read the pair as (key, value).

How: I kept KeyValuePair and gave it the read API of a 2-tuple, instead of returning real tuples. This keeps the for k, v in d|dictsort fast path and the existing p['key']/p['value'] reads and [k: v] pprint form that tests encode. Changes: an int-index overload in SubscriptionVisitor and a ListConverter overload (internal_value.cpp), and a list() overload in ValueConverterImpl (filters.cpp, not in the task's touches, one small addition). Corpus: filters.dictsort_pair_subscript now matches and its allow-list line is deleted; new case filters.dictsort_pair_sequence; 0159 marked done.

Deliberate divergence, filed as 0170 with four pinned corpus cases and allow-list lines: the pair is still not a tuple for in, ==, is sequence/iterable/mapping, truthiness, slicing and +/*. 0170 proposes returning real tuples instead and lists the tests that encode the old form.

Checks: full suite and scripts/preflight.sh --perf pass (instruction gate +0.00%); clang-18 address+undefined passes (GCC sanitizer build fails in untouched src/out_stream.cpp:138, -Werror=stringop-overflow, pre-existing). Roles: verifier, 1 round, no blocking findings; 0 red pushes so far.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NmcpU1qNnJ3txRoN1qqd6Y


Generated by Claude Code

p[0], p[1], p[-1], iteration, |length, |list and |last now work on the
pairs dictsort returns, as they do on Python's tuples.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NmcpU1qNnJ3txRoN1qqd6Y
…s, truthiness

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NmcpU1qNnJ3txRoN1qqd6Y
@rmorozov rmorozov self-assigned this Oct 12, 2026
rmorozov pushed a commit that referenced this pull request Oct 12, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bz1kzjgvkqKWLUE2sD9fzf
rmorozov pushed a commit that referenced this pull request Oct 12, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bz1kzjgvkqKWLUE2sD9fzf
@rmorozov
rmorozov merged commit f3f10cf into master Oct 12, 2026
41 checks passed
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.

2 participants