Skip to content

fix(jinja): recognize mappings in the iterable test - #2891

Open
smg99 wants to merge 1 commit into
huggingface:mainfrom
smg99:fix/jinja-mapping-iterable-test
Open

smg99 wants to merge 1 commit into
huggingface:mainfrom
smg99:fix/jinja-mapping-iterable-test

Conversation

@smg99

@smg99 smg99 commented Nov 19, 2026 •

Copy link
Copy Markdown

{{ value is iterable }} returns false for mappings, although the interpreter already supports iterating their keys. As a result, an iterable guard skips a valid mapping loop.

Include ObjectValue in the test and cover empty/nonempty mappings, other value types, and a guarded key loop. This matches Jinja’s iterable test.

Validation: 772 tests pass across the templates, utilities, interpreter, formatting, and memory suites; Jinja build (including TypeScript declarations), ESLint, formatting, and git diff --check pass. The three mapping regressions fail before the change.

The model-download e2e suite is excluded: this checkout lacks a built @huggingface/hub workspace dependency.


Note

Low Risk
Narrow runtime change to one built-in test predicate plus tests; no auth, I/O, or broad interpreter refactor.

Overview
The built-in iterable test now treats mappings (ObjectValue) as iterable, alongside arrays and strings, so {{ value is iterable }} matches Jinja and guards like {% if value is iterable %}{% for key in value %}… work for dict-like values.

The predicate in runtime.ts was widened to use instanceof for ArrayValue, StringValue, and ObjectValue. New regression tests cover empty/non-empty objects, strings, arrays, and non-iterables, plus a guarded key loop over a mapping.

Reviewed by Cursor Bugbot for commit 9dbc96d. Bugbot is set up for automated code reviews on this repo. Configure here.

@smg99
smg99 requested a review from xenova as a code owner November 19, 2026 05:27
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