[pypy-svn] pypy fast-forward: With Python 2.5, set().remove(anotherset) would raise a KeyError with a frozenset as the key.
amauryfa
commits-noreply at bitbucket.org
Tue Jan 11 22:13:44 CET 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: fast-forward
Changeset: r40592:fdaea10a5a97
Date: 2011-01-11 21:05 +0100
http://bitbucket.org/pypy/pypy/changeset/fdaea10a5a97/
Log: With Python 2.5, set().remove(anotherset) would raise a KeyError
with a frozenset as the key. 2.7 fortunately removed this oddity,
and the KeyError now contains the original 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
@@ -237,11 +237,11 @@
def test_autoconvert_key_error(self):
s = set([frozenset([1, 2]), frozenset([3, 4])])
+ key = set([2, 3])
try:
- s.remove(set([2, 3]))
+ s.remove(key)
except KeyError, e:
- assert isinstance(e.args[0], frozenset)
- assert e.args[0] == frozenset([2, 3])
+ assert e.args[0] is key
def test_contains(self):
letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
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
@@ -411,39 +411,36 @@
"""
Discard an element from a set, with automatic conversion to
frozenset if the argument is a set.
-
- Returns None if successfully removed, otherwise the object that
- wasn't there is returned.
+ Returns True if successfully removed.
"""
try:
del w_left.setdata[w_item]
- return None
+ return True
except KeyError:
- return w_item
+ 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 None
+ return True
except KeyError:
- return w_f
+ return False
except OperationError, e:
if not e.match(space, space.w_TypeError):
raise
- return w_f
-
+ return False
+
def set_discard__Set_ANY(space, w_left, w_item):
_discard_from_set(space, w_left, w_item)
def set_remove__Set_ANY(space, w_left, w_item):
- w_f = _discard_from_set(space, w_left, w_item)
- if w_f is not None:
- space.raise_key_error(w_f)
+ if not _discard_from_set(space, w_left, w_item):
+ space.raise_key_error(w_item)
def hash__Frozenset(space, w_set):
multi = r_uint(1822399083) + r_uint(1822399083) + 1
More information about the Pypy-commit
mailing list