Commit 97979ddc authored by Raymond Hettinger's avatar Raymond Hettinger

* Fix SF #1257731. Make __contains__(), remove(), and discard() only do

  a frozenset conversion when the initial search attempt fails with a
  TypeError and the key is some type of set.  Add a testcase.

* Eliminate a duplicate if-stmt.
parent b02c35e2
...@@ -213,6 +213,19 @@ class TestJointOps(unittest.TestCase): ...@@ -213,6 +213,19 @@ class TestJointOps(unittest.TestCase):
elem.sub = elem elem.sub = elem
elem.set = set([elem]) elem.set = set([elem])
def test_subclass_with_custom_hash(self):
# Bug #1257731
class H(self.thetype):
def __hash__(self):
return id(self)
s=H()
f=set()
f.add(s)
self.assert_(s in f)
f.remove(s)
f.add(s)
f.discard(s)
class TestSet(TestJointOps): class TestSet(TestJointOps):
thetype = set thetype = set
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment