fix: honour a falsey key in all_unique

all_unique applied the key with `map(key, iterable) if key else iterable`, so a falsey callable was silently ignored. it now checks `key is not None` like the other key functions, same fix as #1309.
This commit is contained in:
dualfroz committed 2026-10-07 20:10:16 +02:00
1 parent d1d5e24692
commit 8780c614af
3 files changed
+15 -1

No files matched your search

+1 -1
View File
@@ -4279,7 +4279,7 @@ def all_unique(iterable, key=None):
seenset_add = seenset.add
seenlist = []
seenlist_add = seenlist.append
for element in map(key, iterable) if key else iterable:
for element in map(key, iterable) if key is not None else iterable:
try:
if element in seenset:
return False