All contributions

more-itertools/more-itertools

more-itertools

A Python library with more routines for operating on iterables, beyond the itertools module.

Language
Python
GitHub stars
4,106
Merged changes
1

What we changed

all_unique now uses the given key function even when the function object itself is falsey, instead of silently ignoring it.

What this work shows

  • Callables and __bool__ in Python
  • Helpers for iterables
  • Regression tests with unittest
What was broken

A falsey key was ignored

all_unique applied the key with map(key, iterable) if key else iterable. A callable whose __bool__ returns False was therefore skipped and the function compared items without the key: for ['A', 'B', 'C', 'b'] with a key calling casefold() it returned True.

How we fixed it

A key is None check

The loop now picks iterable if key is None else map(key, iterable), like the other functions with a key parameter in more.py. A test with a CaseFold class, which is falsey and calls casefold(), expects False and fails without the fix.

#1311

Merged change 1

  1. #1311 fix: honour a falsey key in all_unique Merged 17 November 2026

What it taught us

Whether an argument was given is checked against None, not by its truth value, as the other functions with a key parameter in more.py do. The regression test fails without the fix and passes with it.

More about this technology: Python

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.