Repository navigation
Conversation
AlpriElse
marked this pull request as ready for review
November 24, 2026 07:49
Contributor
Author
|
whats up @jasmith-hs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Partially addresses #1240.
Context
CollectionMembershipOperatoris the operator used in this expression1 in [1, 2, 3]Instead of calling the operands o1 and o2, this pull requests will use
<needle> in <collection>Problem
CollectionMembershipOperatorconverted the needle to the type of the first non-null element and then calledcontainsonce.Broken Examples
Confirmed that these semantics don't match Jinja2:
https://gist.github.com/AlpriElse/c70e301761c3b1b525af333fc407fb76
What this PR Does
The needle is now converted to each non-null element's type in turn, still checking with
contains(lists) orcontainsKey(maps); the first match returnstrue. Single-typed collections give the same results as before. Thenullneedle path is unchanged on purpose (see below).Tests
CollectionMembershipOperatorTest:itChecksIfMixedTypeArrayContainsValueanditChecksIfMixedTypeDictionaryContainsKey. Both fail onmasterand pass with this change.CollectionMembershipOperatorTest,CollectionNonMembershipOperatorTestandIsContainingExpTestTestall pass (17 tests).Results for the examples in #1240
Fixed (these now match Jinja2 3.1.6):
2 in ['1', 2]1 in [false, 1]1 in [null, 'abc', 1]'' in [1, '', 2][false, 1] is containing 1#1240 examples kept out of scope (for backwards compatibility)
null type coercion semantics
null in [1, null, 2]nullis converted to the first element's type: it becomes0, and the list has no0null in [0, 1, 2]nullbecomes0, which matches the0Existing tests that depend on the
nullbehavior:IsContainingExpTestTest.itFailsOnNullContainedValue:[1, 2, null] is containing null→ fail (Jinja2: true)IsWithinExpTestTest.itPassesOnNullValueInSequenceis commented out, with a TODO to enable it onceCollectionMembershipOperatorchanges. It expects the Jinja2 behavior:null is within [1, 2, null]→ passstring/number type coercion semantics
1 in ['1', 2]1is converted to the first element's type: it becomes'1', which matches'' in [0, 1, 2]''is converted to a number, which gives0and matchesExisting tests that depend on string/number conversion in
inand its aliases:IsContainingExpTestTest.itPerformsTypeConversion:[1, 2, 3] is containing '2'→ pass (Jinja2: false)IsWithinExpTestTest.itPerformsTypeConversion:'1' is within [100000000000, 1]→ pass (Jinja2: false)IsContainingAllExpTestTest.itPerformsTypeConversion:[1, 2, 3] is containingall ['2', '3']→ pass (Jinja2: false)