Author: Amaury Forgeot d'Arc <amaur...@gmail.com> Branch: Changeset: r46666:2935df8b7559 Date: 2011-08-20 14:45 +0200 http://bitbucket.org/pypy/pypy/changeset/2935df8b7559/
Log: Implement PySet_Contains diff --git a/pypy/module/cpyext/setobject.py b/pypy/module/cpyext/setobject.py --- a/pypy/module/cpyext/setobject.py +++ b/pypy/module/cpyext/setobject.py @@ -44,3 +44,13 @@ raise OperationError(space.w_TypeError, space.wrap("expected set object")) return PySet_GET_SIZE(space, ref) + +@cpython_api([PyObject, PyObject], rffi.INT_real, error=-1) +def PySet_Contains(space, w_obj, w_key): + """Return 1 if found, 0 if not found, and -1 if an error is encountered. Unlike + the Python __contains__() method, this function does not automatically + convert unhashable sets into temporary frozensets. Raise a TypeError if + the key is unhashable. Raise PyExc_SystemError if anyset is not a + set, frozenset, or an instance of a subtype.""" + w_res = space.contains(w_obj, w_key) + return space.int_w(w_res) diff --git a/pypy/module/cpyext/stubs.py b/pypy/module/cpyext/stubs.py --- a/pypy/module/cpyext/stubs.py +++ b/pypy/module/cpyext/stubs.py @@ -1994,15 +1994,6 @@ raise NotImplementedError @cpython_api([PyObject, PyObject], rffi.INT_real, error=-1) -def PySet_Contains(space, anyset, key): - """Return 1 if found, 0 if not found, and -1 if an error is encountered. Unlike - the Python __contains__() method, this function does not automatically - convert unhashable sets into temporary frozensets. Raise a TypeError if - the key is unhashable. Raise PyExc_SystemError if anyset is not a - set, frozenset, or an instance of a subtype.""" - raise NotImplementedError - -@cpython_api([PyObject, PyObject], rffi.INT_real, error=-1) def PySet_Add(space, set, key): """Add key to a set instance. Does not apply to frozenset instances. Return 0 on success or -1 on failure. Raise a TypeError if diff --git a/pypy/module/cpyext/test/test_setobject.py b/pypy/module/cpyext/test/test_setobject.py --- a/pypy/module/cpyext/test/test_setobject.py +++ b/pypy/module/cpyext/test/test_setobject.py @@ -27,3 +27,8 @@ assert api.PySet_Size(w_set) == 5 api.PySet_Discard(w_set, space.wrap(6)) assert api.PySet_Size(w_set) == 4 + + def test_set_contains(self, space, api): + w_set = api.PySet_New(space.wrap([1,2,3,4])) + assert api.PySet_Contains(w_set, space.wrap(1)) + assert not api.PySet_Contains(w_set, space.wrap(0)) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit