Author: Lukas Diekmann <lukas.diekm...@uni-duesseldorf.de> Branch: set-strategies Changeset: r49178:7bc2b4077184 Date: 2011-05-24 15:56 +0200 http://bitbucket.org/pypy/pypy/changeset/7bc2b4077184/
Log: fix and test for fakeobject in has_key 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 @@ -387,8 +387,11 @@ return keys_w def has_key(self, w_set, w_key): + from pypy.objspace.std.dictmultiobject import _is_sane_hash if not self.is_correct_type(w_key): - #XXX switch object strategy, test + if not _is_sane_hash(self.space, w_key): + w_set.switch_to_object_strategy(self.space) + return w_set.has_key(w_key) return False d = self.cast_from_void_star(w_set.sstorage) return self.unwrap(w_key) in d 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 @@ -578,3 +578,20 @@ s.remove(FakeInt(3)) assert s == set([1,2]) raises(KeyError, s.remove, FakeInt(16)) + + + def test_fakeobject_and_has_key(test): + class FakeInt(object): + def __init__(self, value): + self.value = value + def __hash__(self): + return hash(self.value) + + def __eq__(self, other): + if other == self.value: + return True + return False + + s = set([1,2,3,4,5]) + assert 5 in s + assert FakeInt(5) in s _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit