Author: Lukas Diekmann <lukas.diekm...@uni-duesseldorf.de> Branch: set-strategies Changeset: r49141:1e7b0dec4883 Date: 2011-05-01 17:25 +0200 http://bitbucket.org/pypy/pypy/changeset/1e7b0dec4883/
Log: another test for discard; cleaned up discard code diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py --- a/pypy/objspace/std/setobject.py +++ b/pypy/objspace/std/setobject.py @@ -208,6 +208,7 @@ w_set.add(w_key) def delitem(self, w_set, w_item): + # only used internally d = self.cast_from_void_star(w_set.sstorage) try: del d[self.unwrap(w_item)] @@ -702,28 +703,6 @@ x = w_left.discard(w_item) return x - try: - del w_left.setdata[w_item] - return True - except KeyError: - return False - except OperationError, e: - if not e.match(space, space.w_TypeError): - raise - w_f = _convert_set_to_frozenset(space, w_item) - if w_f is None: - raise - - try: - del w_left.setdata[w_f] - return True - except KeyError: - return False - except OperationError, e: - if not e.match(space, space.w_TypeError): - raise - return False - def set_discard__Set_ANY(space, w_left, w_item): _discard_from_set(space, w_left, w_item) diff --git a/pypy/objspace/std/test/test_setobject.py b/pypy/objspace/std/test/test_setobject.py --- a/pypy/objspace/std/test/test_setobject.py +++ b/pypy/objspace/std/test/test_setobject.py @@ -79,6 +79,15 @@ a - b == [1,5] a.__sub__(b) == [1,5] + def test_discard_remove(self): + a = set([1,2,3,4,5]) + a.remove(1) + assert a == set([2,3,4,5]) + a.discard(2) + assert a == set([3,4,5]) + + raises(KeyError, "a.remove(6)") + def test_subtype(self): class subset(set):pass a = subset() _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit