bpo-34149: Behavior of the min/max with key=None (GH-8328)
Improve consistency with the signature for sorted(), heapq.nsmallest(), heapq.nlargest(), and itertools.groupby().
diff --git a/Lib/heapq.py b/Lib/heapq.py
index b31f418..0e3555c 100644
--- a/Lib/heapq.py
+++ b/Lib/heapq.py
@@ -468,10 +468,7 @@
if n == 1:
it = iter(iterable)
sentinel = object()
- if key is None:
- result = min(it, default=sentinel)
- else:
- result = min(it, default=sentinel, key=key)
+ result = min(it, default=sentinel, key=key)
return [] if result is sentinel else [result]
# When n>=size, it's faster to use sorted()
@@ -531,10 +528,7 @@
if n == 1:
it = iter(iterable)
sentinel = object()
- if key is None:
- result = max(it, default=sentinel)
- else:
- result = max(it, default=sentinel, key=key)
+ result = max(it, default=sentinel, key=key)
return [] if result is sentinel else [result]
# When n>=size, it's faster to use sorted()