[Python-Dev] weakref (or doc) bug?

David Abrahams David Abrahams" <david.abrahams@rcn.com
Tue, 2 Jul 2002 14:09:42 -0400


>>> help(weakref.ref)
Help on built-in function ref:

ref(...)
    new(object[, callback]) -- create a weak reference to 'object';
    when 'object' is finalized, 'callback' will be called and passed
    a reference to 'object'.
    ^^^^^^^^^^^^^^^^^^^^^^^

This appears to be a lie, or at least misleadingly phrased, in Python
2.2.1:

>>> class Z: pass
...
>>> def dying(x): print x, 'is dying'
...
>>> z = Z()
>>> r = weakref.ref(z, dying)
>>> z = 1
<weakref at 9826f8; dead> is dying

It appears that it's a reference to the weakref object that's passed, not
the dying object itself.

What's the intention?

TIA,
Dave

+---------------------------------------------------------------+
                  David Abrahams
      C++ Booster (http://www.boost.org)               O__  ==
      Pythonista (http://www.python.org)              c/ /'_ ==
  resume: http://users.rcn.com/abrahams/resume.html  (*) \(*) ==
          email: david.abrahams@rcn.com
+---------------------------------------------------------------+