Skip to content

Honor falsey callable keys in redundant - #554

Closed
Gambit-Checkmate wants to merge 1 commit into
mahmoud:masterfrom
Gambit-Checkmate:fix/redundant-falsey-key
Closed

Gambit-Checkmate wants to merge 1 commit into
mahmoud:masterfrom
Gambit-Checkmate:fix/redundant-falsey-key

Conversation

@Gambit-Checkmate

@Gambit-Checkmate Gambit-Checkmate commented Oct 7, 2026 •

Copy link
Copy Markdown

The change

Honor callable redundant keys regardless of their boolean value. The function already accepts them in validation, but a subsequent truthiness check silently bypasses them, producing incorrect duplicates and raising TypeError on unhashable values. Distinguish an omitted key (None) from a supplied key, and document that contract.

Three regressions cover falsey __bool__ callables in both result modes, one call per item with generator input, and a zero-length callable normalizing unhashable lists. All three fail before the patch; python -m pytest --doctest-modules boltons tests -q passes after it: 681 tests and 12 subtests on Windows/Python 3.13.13. No runtime dependencies added.

The backstory

Like #551 and #552, this was investigated by Codex at the account owner's request to contribute tested fixes to established projects. This is a separate bug from sorting-key evaluation: redundant disagrees with its documented complement unique on a valid callable input. I do not claim personal human usage experience; the reproduction and regressions were run against current master.

AI assistance

  • Harness/tooling: Codex, GitHub CLI, Python and pytest.
  • Model(s): OpenAI GPT-6.
  • Original prompt(s): “每天要提交pr,今天还是提交两个”. The standing task requires upstream repositories with at least 1,000 stars, duplicate checks, real changes, sufficient validation and verified write permissions before submission.

Fixes #553.

GitHub Actions is awaiting maintainer approval for this external contribution (action_required): https://github.com/mahmoud/boltons/actions/runs/37569645832 . Local full validation passed; hosted documentation build is pending.

@Saadia751 Saadia751 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A falsey callable now works with unhashable dictionary inputs as well as ordinary values. I checked duplicate transformed keys with and without groups=True; the complete group keeps the first occurrence and its later matches, while the default result retains the first redundant occurrence.

Checked 3d93b2d3b181 with standalone Python 3.12.14 checks (3 passing assertions). I haven't run the full upstream suite.

mahmoud added a commit that referenced this pull request Oct 25, 2026
…ize, falsey keys, key-once untyped_sorted, negative maxsplit, fractional backoff; add chunked_filter (#585, #569, #563, #554, #552, #502, #496, #491)
@mahmoud

mahmoud commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Folded into #609 (see the PR description for credit). Thanks for the report and the repro.

@mahmoud mahmoud closed this Oct 25, 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.

redundant ignores callable keys with a false boolean value

3 participants