mirror of
https://github.com/python/cpython.git
synced 2025-11-03 15:11:34 +00:00
#10360: catch TypeError in WeakSet.__contains__, just like WeakKeyDictionary does.
This commit is contained in:
parent
3b9406b08a
commit
f8de3fea12
3 changed files with 10 additions and 2 deletions
|
|
@ -66,7 +66,11 @@ def __len__(self):
|
||||||
return sum(x() is not None for x in self.data)
|
return sum(x() is not None for x in self.data)
|
||||||
|
|
||||||
def __contains__(self, item):
|
def __contains__(self, item):
|
||||||
return ref(item) in self.data
|
try:
|
||||||
|
wr = ref(item)
|
||||||
|
except TypeError:
|
||||||
|
return False
|
||||||
|
return wr in self.data
|
||||||
|
|
||||||
def __reduce__(self):
|
def __reduce__(self):
|
||||||
return (self.__class__, (list(self),),
|
return (self.__class__, (list(self),),
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,8 @@ def test_len(self):
|
||||||
def test_contains(self):
|
def test_contains(self):
|
||||||
for c in self.letters:
|
for c in self.letters:
|
||||||
self.assertEqual(c in self.s, c in self.d)
|
self.assertEqual(c in self.s, c in self.d)
|
||||||
self.assertRaises(TypeError, self.s.__contains__, [[]])
|
# 1 is not weakref'able, but that TypeError is caught by __contains__
|
||||||
|
self.assertNotIn(1, self.s)
|
||||||
self.assertIn(self.obj, self.fs)
|
self.assertIn(self.obj, self.fs)
|
||||||
del self.obj
|
del self.obj
|
||||||
self.assertNotIn(ustr('F'), self.fs)
|
self.assertNotIn(ustr('F'), self.fs)
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #10360: In WeakSet, do not raise TypeErrors when testing for
|
||||||
|
membership of non-weakrefable objects.
|
||||||
|
|
||||||
- Issue #940286: pydoc.Helper.help() ignores input/output init parameters.
|
- Issue #940286: pydoc.Helper.help() ignores input/output init parameters.
|
||||||
|
|
||||||
- Issue #1745035: Add a command size and data size limit to smtpd.py, to
|
- Issue #1745035: Add a command size and data size limit to smtpd.py, to
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue