[Zodb-checkins] SVN: ZODB/trunk/src/ Make PersistentList's sort method accept keyword parameters.

Patrick Strawderman patrick at zope.com
Mon Aug 24 11:30:11 EDT 2009


Log message for revision 103159:
  Make PersistentList's sort method accept keyword parameters.
  

Changed:
  U   ZODB/trunk/src/CHANGES.txt
  U   ZODB/trunk/src/persistent/list.py
  U   ZODB/trunk/src/persistent/tests/test_list.py

-=-
Modified: ZODB/trunk/src/CHANGES.txt
===================================================================
--- ZODB/trunk/src/CHANGES.txt	2009-08-24 15:29:02 UTC (rev 103158)
+++ ZODB/trunk/src/CHANGES.txt	2009-08-24 15:30:11 UTC (rev 103159)
@@ -25,6 +25,10 @@
 - Opening a blob with modes 'r+' or 'a' would fail when the blob had no
   committed changes.
 
+- PersistentList's sort method did not allow passing of keyword parameters.
+  Changed its sort parameter list to match that of its (Python 2.4+)
+  UserList base class.
+
 3.9.0b5 (2009-08-06)
 ====================
 

Modified: ZODB/trunk/src/persistent/list.py
===================================================================
--- ZODB/trunk/src/persistent/list.py	2009-08-24 15:29:02 UTC (rev 103158)
+++ ZODB/trunk/src/persistent/list.py	2009-08-24 15:30:11 UTC (rev 103159)
@@ -81,8 +81,8 @@
         self.__super_reverse()
         self._p_changed = 1
 
-    def sort(self, *args):
-        self.__super_sort(*args)
+    def sort(self, *args, **kwargs):
+        self.__super_sort(*args, **kwargs)
         self._p_changed = 1
 
     def extend(self, other):

Modified: ZODB/trunk/src/persistent/tests/test_list.py
===================================================================
--- ZODB/trunk/src/persistent/tests/test_list.py	2009-08-24 15:29:02 UTC (rev 103158)
+++ ZODB/trunk/src/persistent/tests/test_list.py	2009-08-24 15:30:11 UTC (rev 103159)
@@ -217,6 +217,24 @@
         u.sort()
         eq(u, u2, "u == u2")
 
+        # Test keyword arguments to sort
+        u.sort(cmp=lambda x,y: cmp(y, x))
+        eq(u, [1, 0], "u == [1, 0]")
+
+        u.sort(key=lambda x:-x)
+        eq(u, [1, 0], "u == [1, 0]")
+
+        u.sort(reverse=True)
+        eq(u, [1, 0], "u == [1, 0]")
+
+        # Passing any other keyword arguments results in a TypeError
+        try:
+            u.sort(blah=True)
+        except TypeError:
+            pass
+        else:
+            raise TestFailed("expected TypeError")
+
         # Test extend
 
         u = u1[:]



More information about the Zodb-checkins mailing list