Author: Armin Rigo <[email protected]>
Branch:
Changeset: r94308:0dafeea23cbb
Date: 2018-04-12 09:33 +0200
http://bitbucket.org/pypy/pypy/changeset/0dafeea23cbb/
Log: Issue #2797
Fix for PySet_Discard()
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
@@ -1,4 +1,4 @@
-from pypy.interpreter.error import oefmt
+from pypy.interpreter.error import OperationError, oefmt
from rpython.rtyper.lltypesystem import rffi, lltype
from pypy.module.cpyext.api import (cpython_api, Py_ssize_t, CANNOT_FAIL,
build_type_checkers)
@@ -64,8 +64,13 @@
instance of set or its subtype."""
if not PySet_Check(space, w_s):
PyErr_BadInternalCall(space)
- space.call_method(space.w_set, 'discard', w_s, w_obj)
- return 0
+ try:
+ space.call_method(space.w_set, 'remove', w_s, w_obj)
+ except OperationError as e:
+ if e.match(space, space.w_KeyError):
+ return 0
+ raise
+ return 1
@cpython_api([PyObject], PyObject)
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
@@ -28,7 +28,11 @@
assert api.PySet_Size(w_set) == 4
api.PySet_Add(w_set, space.wrap(6))
assert api.PySet_Size(w_set) == 5
- api.PySet_Discard(w_set, space.wrap(6))
+ res = api.PySet_Discard(w_set, space.wrap(6))
+ assert res == 1
+ assert api.PySet_Size(w_set) == 4
+ res = api.PySet_Discard(w_set, space.wrap(6))
+ assert res == 0
assert api.PySet_Size(w_set) == 4
def test_set_contains(self, space, api):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit