[New-bugs-announce] [issue5964] WeakSet cmp methods

Robert Schuppenies report at bugs.python.org
Fri May 8 03:07:22 CEST 2009

New submission from Robert Schuppenies <robert.schuppenies at gmail.com>:

Running this code:

>>> import weakref
>>> class C: pass
>>> ws = weakref.WeakSet([C])
>>> if ws == 1:
...      print(1)

gives me the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    File "/home/bob/python/svn/py3k/Lib/_weakrefset.py", line 121, in __eq__
        return self.data == set(ref(item) for item in other)
        TypeError: 'int' object is not iterable

Looking at _weakrefset.py line 121 gives

  def __eq__(self, other):
      return self.data == set(ref(item) for item in other)

which treats any 'other' object as a set like object. Therefore
comparing WeakSet to a non-set-like object always fails.

Do I understand it correctly and if so, is this the intended behavior?

components: Library (Lib)
messages: 87420
nosy: schuppenies
severity: normal
status: open
title: WeakSet cmp methods
type: behavior
versions: Python 3.0, Python 3.1

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list