[pypy-svn] r74209 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test
afa at codespeak.net
afa at codespeak.net
Thu Apr 29 00:45:51 CEST 2010
Author: afa
Date: Thu Apr 29 00:45:50 2010
New Revision: 74209
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/dictobject.py
pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_dictobject.py
Log:
PyDict_Update, PyDict_Copy
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/dictobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/dictobject.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/dictobject.py Thu Apr 29 00:45:50 2010
@@ -73,6 +73,20 @@
space.call_method(w_obj, "clear")
@cpython_api([PyObject], PyObject)
+def PyDict_Copy(space, w_obj):
+ """Return a new dictionary that contains the same key-value pairs as p.
+ """
+ return space.call_method(w_obj, "copy")
+
+ at cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
+def PyDict_Update(space, w_obj, w_other):
+ """This is the same as PyDict_Merge(a, b, 1) in C, or a.update(b) in
+ Python. Return 0 on success or -1 if an exception was raised.
+ """
+ space.call_method(w_obj, "update", w_other)
+ return 0
+
+ at cpython_api([PyObject], PyObject)
def PyDict_Keys(space, w_obj):
"""Return a PyListObject containing all the keys from the dictionary,
as in the dictionary method dict.keys()."""
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py Thu Apr 29 00:45:50 2010
@@ -799,12 +799,6 @@
"""
raise NotImplementedError
- at cpython_api([PyObject], PyObject)
-def PyDict_Copy(space, p):
- """Return a new dictionary that contains the same key-value pairs as p.
- """
- raise NotImplementedError
-
@cpython_api([PyObject, rffi.CCHARP], rffi.INT_real, error=-1)
def PyDict_DelItemString(space, p, key):
"""Remove the entry in dictionary p which has a key specified by the string
@@ -822,13 +816,6 @@
"""
raise NotImplementedError
- at cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
-def PyDict_Update(space, a, b):
- """This is the same as PyDict_Merge(a, b, 1) in C, or a.update(b) in
- Python. Return 0 on success or -1 if an exception was raised.
- """
- raise NotImplementedError
-
@cpython_api([PyObject, PyObject, rffi.INT_real], rffi.INT_real, error=-1)
def PyDict_MergeFromSeq2(space, a, seq2, override):
"""Update or merge into dictionary a, from the key-value pairs in seq2.
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_dictobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_dictobject.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_dictobject.py Thu Apr 29 00:45:50 2010
@@ -60,3 +60,14 @@
assert space.eq_w(api.PyDict_Values(w_d), space.wrap(["b"]))
assert space.eq_w(api.PyDict_Items(w_d), space.wrap([("a", "b")]))
+ def test_update(self, space, api):
+ w_d = space.newdict()
+ space.setitem(w_d, space.wrap("a"), space.wrap("b"))
+
+ w_d2 = api.PyDict_Copy(w_d)
+ assert not space.is_w(w_d2, w_d)
+ space.setitem(w_d, space.wrap("c"), space.wrap("d"))
+ space.setitem(w_d2, space.wrap("e"), space.wrap("f"))
+
+ api.PyDict_Update(w_d, w_d2)
+ assert space.unwrap(w_d) == dict(a='b', c='d', e='f')
More information about the Pypy-commit
mailing list