This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: _weakrefset.WeakSet.__contains__ should not propagate TypeErrors
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 2.7
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, michael.foord, pitrou, rhettinger, tseaver
Priority: normal Keywords: patch

Created on 2010-11-08 14:12 by tseaver, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue10360-redux.patch tseaver, 2010-11-08 16:58
Messages (16)
msg120743 - (view) Author: Tres Seaver (tseaver) * Date: 2010-11-08 14:12
Because application code which tests for the presence of
an object in a WeakSet may not be able to ensure that the
object is weak-referenceable, the set should just return
False for any object passed to '__contains__' which causes
'ref' to raise a TypeError.

Patch forthcoming.
msg120768 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-11-08 16:35
A result from IRC is that to be consistent with normal sets, only TypeErrors coming from ref() should be caught, but not those TypeErrors from the actual membership test (i.e. the hash functioon of the value).
msg120770 - (view) Author: Tres Seaver (tseaver) * Date: 2010-11-08 16:53
A new version of the patch, which only traps TypeErrors raises
by ref(item).  The test now ensures that hashing errors are
propagated, for compatibility with standard sets.
msg120771 - (view) Author: Tres Seaver (tseaver) * Date: 2010-11-08 16:58
"One more time, with feeling."

Sorry for the noise, the last patch was not against the 2.7 trunk.
msg120772 - (view) Author: Tres Seaver (tseaver) * Date: 2010-11-08 17:06
FTR, the patch applies cleanly to the py3k branch, too. (Michael
pointed out that the original code was copied directly from there).
msg120774 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-11-08 17:11
What is the behaviour of WeakKeyDictionary here? I don't really agree that TypeError should be silenced.
msg120779 - (view) Author: Tres Seaver (tseaver) * Date: 2010-11-08 17:20
WeakKeyDictionary's __contains__:

    def __contains__(self, key):
        try:
            wr = ref(key)
        except TypeError:
            return 0
        return wr in self.data
msg122033 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-11-22 00:10
I don't have any other insights on this one.  Assigned by to Antoine who appears to have put some thought into it.
msg122036 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-11-22 00:13
Well if WeakKeyDictionary silences the TypeError from ref(), it sounds consistent for WeakSet to silence it too.
msg123199 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-12-03 07:56
I agree; committed in r86960.

If anyone wants to change this to raise TypeError for objects that are both unhashable and unrefable, please speak up.
msg123249 - (view) Author: Tres Seaver (tseaver) * Date: 2010-12-03 14:19
This fix needs backporting to the 3.1 and 2.7 branches as well.
msg123252 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-12-03 15:20
Don't worry, it will be ported.
msg127614 - (view) Author: Tres Seaver (tseaver) * Date: 2011-01-31 16:34
georg.brandl (2010-12-03 10:20):

> Don't worry, it will be ported.

When?  Why would it *not* be merged to the 2.7 and 3.1 branches at the
time the bug is closed?  Delaying the port only increases the chance
that the fix will fall between the cracks.

In particular, I would like confirmation that the fix *will* be ported
before 2.7.2 is released:  this bug causes the 2.7 Zope buildbots
to fail, which means they are disabled until the fix is released.
msg127615 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-01-31 16:42
Let's reopen until then.
msg127643 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2011-01-31 18:59
Because I don't think porting every change immediately is worth my time when I can do it much faster in mass-merges.

I know other developers do this differently, but since I use svnmerge to do my mass-merges, there won't be any falling through cracks.
msg129351 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2011-02-25 10:57
Backported to 3.1 in r88556, and 2.7 in r88564.
History
Date User Action Args
2022-04-11 14:57:08adminsetgithub: 54569
2011-02-25 10:57:48georg.brandlsetstatus: open -> closed
nosy: georg.brandl, rhettinger, tseaver, pitrou, michael.foord
messages: + msg129351
2011-01-31 18:59:58georg.brandlsetnosy: georg.brandl, rhettinger, tseaver, pitrou, michael.foord
messages: + msg127643
2011-01-31 16:42:10pitrousetstatus: closed -> open

assignee: pitrou ->
versions: - Python 3.2
nosy: georg.brandl, rhettinger, tseaver, pitrou, michael.foord
messages: + msg127615
resolution: fixed -> accepted
stage: resolved
2011-01-31 16:34:14tseaversetnosy: georg.brandl, rhettinger, tseaver, pitrou, michael.foord
messages: + msg127614
2010-12-03 15:20:43georg.brandlsetstatus: open -> closed

messages: + msg123252
2010-12-03 14:19:51tseaversetstatus: closed -> open

messages: + msg123249
2010-12-03 07:56:46georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg123199
2010-11-22 00:13:33pitrousetmessages: + msg122036
2010-11-22 00:10:21rhettingersetassignee: rhettinger -> pitrou
messages: + msg122033
2010-11-08 17:20:15tseaversetmessages: + msg120779
2010-11-08 17:11:08pitrousetnosy: + pitrou

messages: + msg120774
versions: + Python 3.2
2010-11-08 17:07:01tseaversetversions: + Python 3.1
2010-11-08 17:06:39tseaversetmessages: + msg120772
2010-11-08 16:58:25tseaversetfiles: + issue10360-redux.patch

messages: + msg120771
2010-11-08 16:57:48tseaversetfiles: - issue10360-redux.patch
2010-11-08 16:53:57tseaversetfiles: + issue10360-redux.patch

messages: + msg120770
2010-11-08 16:52:43tseaversetfiles: - issue10360.patch
2010-11-08 16:35:55georg.brandlsetassignee: rhettinger

messages: + msg120768
nosy: + rhettinger, georg.brandl
2010-11-08 16:22:46michael.foordsetnosy: + michael.foord
2010-11-08 14:26:13tseaversetfiles: + issue10360.patch
keywords: + patch
components: + Library (Lib)
2010-11-08 14:12:42tseavercreate