summaryrefslogtreecommitdiffstats
path: root/Lib/heapq.py
diff options
context:
space:
mode:
authorAlexander Marshalov <_@marshalov.org>2018-07-24 03:58:21 (GMT)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>2018-07-24 03:58:21 (GMT)
commite22072fb11246f125aa9ff7629c832b9e2407ef0 (patch)
tree8cbe81568e233643182d0c952b62c6fdf3ba060a /Lib/heapq.py
parentbde782bb594edffeabe978abeee2b7082ab9bc2a (diff)
downloadcpython-e22072fb11246f125aa9ff7629c832b9e2407ef0.zip
cpython-e22072fb11246f125aa9ff7629c832b9e2407ef0.tar.gz
cpython-e22072fb11246f125aa9ff7629c832b9e2407ef0.tar.bz2
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().
Diffstat (limited to 'Lib/heapq.py')
-rw-r--r--Lib/heapq.py10
1 files changed, 2 insertions, 8 deletions
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 @@ def nsmallest(n, iterable, key=None):
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 @@ def nlargest(n, iterable, key=None):
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()