New in version 2.1.
The weakref module allows the Python programmer to create weak references to objects.
XXX -- need to say more here!
Not all objects can be weakly referenced; those objects which do include class instances, functions written in Python (but not in C), and methods (both bound and unbound). Extension types can easily be made to support weak references; see section 3.3.2, ``Weak References in Extension Types,'' for more information.
It is allowable for many weak references to be constructed for the same object. Callbacks registered for each weak reference will be called from the most recently registered callback to the oldest registered callback.
Exceptions raised by the callback will be noted on the standard error output, but cannot be propagated; they are handled in exactly the same way as exceptions raised from an object's __del__() method.
Weak references are hashable if the object is hashable. They will maintain their hash value even after the object was deleted. If hash() is called the first time only after the object was deleted, the call will raise TypeError.
Weak references support test for equality, but not ordering. If the object is still alive, to references are equal if the objects are equal (regardless of the callback). If the object has been deleted, they are equal iff they are identical.
None, the new dictionary will contain the items contained in
dict. The values from dict must be weakly referencable;
if any values which would be inserted into the new mapping are not
weakly referencable, TypeError will be raised and the
new mapping will be empty.
If the weakkeys argument is not given or zero, the values in the dictionary are weak. That means the entries in the dictionary will be discarded when no strong reference to the value exists anymore.
If the weakkeys argument is nonzero, the keys in the dictionary are weak, i.e. the entry in the dictionary is discarded when the last strong reference to the key is discarded.
ProxyType or
CallableProxyType, depending on whether object is
callable. Proxy objects are not hashable regardless of the
referent; this avoids a number of problems related to their
fundamentally mutable nature, and prevent their use as dictionary
keys. callable is the same as the parameter of the same name
to the ref() function.
See Also: