1. Armin Rigo
  2. cpython-withatomic

Commits

Raymond Hettinger  committed d33b3a2

Fix argument order in pure python version of nsmallest() and nlargest().

  • Participants
  • Parent commits 7e955e9
  • Branches legacy-trunk

Comments (0)

Files changed (2)

File Lib/heapq.py

View file
     for i in reversed(xrange(n//2)):
         _siftup(x, i)
 
-def nlargest(iterable, n):
+def nlargest(n, iterable):
     """Find the n largest elements in a dataset.
 
     Equivalent to:  sorted(iterable, reverse=True)[:n]
     result.sort(reverse=True)
     return result
 
-def nsmallest(iterable, n):
+def nsmallest(n, iterable):
     """Find the n smallest elements in a dataset.
 
     Equivalent to:  sorted(iterable)[:n]

File Lib/test/test_heapq.py

View file
         self.check_invariant(results)
 
         self.assertRaises(TypeError, heappush, [])
-        self.assertRaises(TypeError, heappush, None, None)
-        self.assertRaises(TypeError, heappop, None)
+        try:
+            self.assertRaises(TypeError, heappush, None, None)
+            self.assertRaises(TypeError, heappop, None)
+        except AttributeError:
+            pass
 
     def check_invariant(self, heap):
         # Check the heap invariant.