Commit 20322290 authored by Thomas Lotze's avatar Thomas Lotze

merging revision 40330 from trunk:

- fixed the API of the pop() method on PersistentDict and PersistentMapping
- no longer try to find pop and popitem on UserDict as all supported
  Python versions have them
- added a test for the default argument of pop()
- added a NEWS.txt entry about pop()
parent b16a1c9e
......@@ -109,6 +109,9 @@ Multidatabase
PersistentMapping
-----------------
- (3.6b3) The ``PersistentMapping`` makes changes by a ``pop()`` method call
persistent now.
- (3.6a1) The ``PersistentMapping`` class has an ``__iter__()`` method
now, so that objects of this type work well with Python's iteration
protocol. For example, if ``x`` is a ``PersistentMapping`` (or
......
......@@ -73,9 +73,9 @@ class PersistentDict(persistent.Persistent, IterableUserDict):
self._p_changed = True
return self.__super_setdefault(key, failobj)
def pop(self, i):
def pop(self, key, *args):
self._p_changed = True
return self.__super_pop(i)
return self.__super_pop(key, *args)
def popitem(self):
self._p_changed = True
......
......@@ -41,6 +41,8 @@ class PersistentMapping(UserDict, persistent.Persistent):
__super_clear = UserDict.clear
__super_update = UserDict.update
__super_setdefault = UserDict.setdefault
__super_pop = UserDict.pop
__super_popitem = UserDict.popitem
def __delitem__(self, key):
self.__super_delitem(key)
......@@ -66,23 +68,13 @@ class PersistentMapping(UserDict, persistent.Persistent):
self._p_changed = 1
return self.__super_setdefault(key, failobj)
try:
__super_pop = UserDict.pop
except AttributeError:
pass
else:
def pop(self, i):
self._p_changed = 1
return self.__super_pop(i)
try:
__super_popitem = UserDict.popitem
except AttributeError:
pass
else:
def popitem(self):
self._p_changed = 1
return self.__super_popitem()
def pop(self, key, *args):
self._p_changed = 1
return self.__super_pop(key, *args)
def popitem(self):
self._p_changed = 1
return self.__super_popitem()
# __iter__ was added in ZODB 3.4.2, but should have been added long
# before. We could inherit from Python's IterableUserDict instead
......
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# Copyright (c) 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
......@@ -136,6 +136,9 @@ class TestPMapping(unittest.TestCase):
else:
raise TestFailed("1 should not be poppable from u2")
x = u2.pop(1, 7)
eq(x, 7, "u2.pop(1, 7) == 7")
# Test popitem
items = u2.items()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment