[Python-checkins] cpython (merge 3.2 -> default): Merge

raymond.hettinger python-checkins at python.org
Sun Oct 30 22:33:53 CET 2011


http://hg.python.org/cpython/rev/e475064fd1ed
changeset:   73223:e475064fd1ed
parent:      73219:197d703fb23e
parent:      73222:155e57a449b5
user:        Raymond Hettinger <python at rcn.com>
date:        Sun Oct 30 14:33:31 2011 -0700
summary:
  Merge

files:
  Lib/heapq.py |  4 ++++
  1 files changed, 4 insertions(+), 0 deletions(-)


diff --git a/Lib/heapq.py b/Lib/heapq.py
--- a/Lib/heapq.py
+++ b/Lib/heapq.py
@@ -185,6 +185,8 @@
 
     Equivalent to:  sorted(iterable, reverse=True)[:n]
     """
+    if n < 0:
+        return []
     it = iter(iterable)
     result = list(islice(it, n))
     if not result:
@@ -201,6 +203,8 @@
 
     Equivalent to:  sorted(iterable)[:n]
     """
+    if n < 0:
+        return []
     if hasattr(iterable, '__len__') and n * 10 <= len(iterable):
         # For smaller values of n, the bisect method is faster than a minheap.
         # It is also memory efficient, consuming only n elements of space.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list