| Python Library Reference |
New in version 2.1.
Theweakref module allows the Python programmer to createweak references to objects.
In the discussion which follows, the termreferent means theobject which is referred to by a weak reference.
XXX -- need to say more here!
Not all objects can be weakly referenced; those objects which doinclude class instances, functions written in Python (but not in C),and methods (both bound and unbound). Extension types can easilybe made to support weak references; see section3.3.3,``Weak References in Extension Types,'' for more information.
None to be returned. Ifcallback is provided, it will be called when the object is about to be finalized; the weak reference object will be passed as the only parameter to the callback; the referent will no longer be available.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 theobject is hashable. They will maintain their hash value even after theobject was deleted. Ifhash() is called the first time only after theobject was deleted, the call will raiseTypeError.
Weak references support tests for equality, but not ordering. If the referents are still alive, two references have the same equality relationship as their referents (regardless of thecallback). If either referent has been deleted, the references are equal only if the reference objects are the same object.
ProxyType orCallableProxyType, depending on whetherobject 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.callback is the same as the parameter of the same name to theref() function.See Also:
| Python Library Reference |