Python: fix(core): keep booleans distinct from numbers inside sets - #8681
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit intoSep 24, 2026
Conversation
filter_values_equal distinguishes True from 1 for scalars, sequences and
mappings, but sets fell through to plain `==`, where `{1} == {True}` is
true in Python. require_filter_collection accepts sets, and
_evaluate_filter uses this for eq/ne/in/contains, so a record holding
{1} matched a filter looking for {True}.
Compare set members by a key that marks bools, recursing through the
hashable containers a set can hold. Ints and floats still compare equal,
and a set still equals an equal frozenset.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WyCUJcDPnCnQMmuDwsnDmD
Anish Mehta (anishmehta24)
deployed
to
github-app-auth
September 23, 2026 10:34 — with
GitHub Actions
Active
Anish Mehta (anishmehta24)
deployed
to
github-app-auth
September 23, 2026 10:35 — with
GitHub Actions
Active
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Sep 24, 2026
Eduard van Valkenburg (eavanvalkenburg)
left a comment
Member
There was a problem hiding this comment.
Anish Mehta (@anishmehta24) The current head is green, and the dedicated full-diff review found no remaining actionable issues with the strict boolean/number set comparison change.
This branch was successfully deployed
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.
Motivation & Context
filter_values_equalkeeps booleans distinct from numbers for scalars, sequences and mappings, but not for sets — andrequire_filter_collectionaccepts sets and frozensets as filter values:A set cannot be walked pairwise the way the sequence branch walks a list, so it fell through to plain
==, and{1} == {True}is true in Python becauseTruehashes and compares equal to1.It reaches real filtering:
_evaluate_filteruses this foreq,ne,in,not_in,contains,contains_anyandcontains_all, so a record whose field is{1}matched a filter looking for{True}.Description & Review Guide
filter_values_equalthat compares members by_set_member_key, which tags bools and recurses through the hashable containers a set can hold (tuples, frozensets). When only one side is a set, native==still decides, so a set never equals a list or a mapping.{True}no longer equals{1}. Everything else is unchanged:{1}still equals{1.0}(ints and floats stay interchangeable, matching the existing scalar case), and{1}still equalsfrozenset({1}), which Python compares equal by contents.Tests: ten cases added to the existing
test_filter_values_equal_preserves_nested_typestable, which had no set or frozenset case at all — the bool/int pairs forset,frozensetand a nested tuple, plus the unchanged behaviour ({1}/{1.0}, ordering, length mismatch, empty, set vs frozenset, set vs list). Five fail onmain.test_vectors.py194 passed.poe fmt,poe lint,poe typing -P coreclean.Related Issue
Fixes #8679
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.🤖 Generated with Claude Code