1. idank
  2. sqlalchemy

Commits

jason kirtland  committed 585da69

Added default support to OrderedDict.pop [ticket:585]

  • Participants
  • Parent commits 14efc2e
  • Branches default

Comments (0)

Files changed (2)

File lib/sqlalchemy/util.py

View file
  • Ignore whitespace
         dict.__delitem__(self, key)
         self._list.remove(key)
 
-    def pop(self, key):
-        value = dict.pop(self, key)
-        self._list.remove(key)
+    def pop(self, key, *default):
+        present = key in self
+        value = dict.pop(self, key, *default)
+        if present:
+            self._list.remove(key)
         return value
 
     def popitem(self):

File test/base/utils.py

View file
  • Ignore whitespace
         eq_(o.values(), [1, 2, 'attack', 3])
 
         o.pop('snack')
+        eq_(o.keys(), ['a', 'b', 'c'])
+        eq_(o.values(), [1, 2, 3])
+
+        try:
+            o.pop('eep')
+            assert False
+        except KeyError:
+            pass
+
+        eq_(o.pop('eep', 'woot'), 'woot')
+
+        try:
+            o.pop('whiff', 'bang', 'pow')
+            assert False
+        except TypeError:
+            pass
 
         eq_(o.keys(), ['a', 'b', 'c'])
         eq_(o.values(), [1, 2, 3])