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 and dictionaries. Extension types can easily
be made to support weak references; see section
Warning: The weak dictionaries provided in the current implementation and described below are subject to change. They are included to solicit feedback and usage experience, and may be changed or removed in the final version.
Warning: The desired semantics of weak-reference proxy objects are not completely clear; it is very difficult to create proxies which behave exactly like the type of the referent. The details of these objects are likely to change to some degree before the final release as experience reports become available.
Please send specific feeback on this module to Fred Drake at fdrake@acm.org.
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 propogated; they are handled in exactly the same way as exceptions raised from an object's __del__() method.
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.
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: