[Python-checkins] r86960 - in python/branches/py3k: Lib/_weakrefset.py Lib/test/test_weakset.py Misc/NEWS
georg.brandl
python-checkins at python.org
Fri Dec 3 08:55:44 CET 2010
Author: georg.brandl
Date: Fri Dec 3 08:55:44 2010
New Revision: 86960
Log:
#10360: catch TypeError in WeakSet.__contains__, just like WeakKeyDictionary does.
Modified:
python/branches/py3k/Lib/_weakrefset.py
python/branches/py3k/Lib/test/test_weakset.py
python/branches/py3k/Misc/NEWS
Modified: python/branches/py3k/Lib/_weakrefset.py
==============================================================================
--- python/branches/py3k/Lib/_weakrefset.py (original)
+++ python/branches/py3k/Lib/_weakrefset.py Fri Dec 3 08:55:44 2010
@@ -66,7 +66,11 @@
return sum(x() is not None for x in self.data)
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):
return (self.__class__, (list(self),),
Modified: python/branches/py3k/Lib/test/test_weakset.py
==============================================================================
--- python/branches/py3k/Lib/test/test_weakset.py (original)
+++ python/branches/py3k/Lib/test/test_weakset.py Fri Dec 3 08:55:44 2010
@@ -50,7 +50,8 @@
def test_contains(self):
for c in self.letters:
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)
del self.obj
self.assertNotIn(ustr('F'), self.fs)
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Fri Dec 3 08:55:44 2010
@@ -33,6 +33,9 @@
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 #1745035: Add a command size and data size limit to smtpd.py, to
More information about the Python-checkins
mailing list