@@ -3,6 +3,8 @@ \section{\module{weakref} ---
33
44\declaremodule {extension}{weakref}
55\moduleauthor {Fred L. Drake, Jr.}{
[email protected] }
6+ \moduleauthor {Neil Schemenauer}{
[email protected] }
7+ \moduleauthor {Martin von L
\o "wis}{
[email protected] }
68\sectionauthor {Fred L. Drake, Jr.}{
[email protected] }
79
810\versionadded {2.1}
@@ -18,23 +20,13 @@ \section{\module{weakref} ---
1820be made to support weak references; see section \ref {weakref-extension },
1921`` Weak References in Extension Types,'' for more information.
2022
21-
22- \strong {Warning:}
23- The weak dictionaries provided in the current implementation and
24- described below are subject to change. They are included to solicit
25- feedback and usage experience, and may be changed or removed in the
26- final version.
27-
2823\strong {Warning:}
2924The desired semantics of weak-reference proxy objects are not
3025completely clear; it is very difficult to create proxies which behave
3126exactly like the type of the referent. The details of these objects
3227are likely to change to some degree before the final release as
3328experience reports become available.
3429
35- Please send specific feedback on this module to Fred Drake at
36- 37-
3830
3931\begin {funcdesc }{ref}{object\optional {, callback}}
4032 Return a weak reference to \var {object}. If \var {callback} is
@@ -53,15 +45,36 @@ \section{\module{weakref} ---
5345 error output, but cannot be propagated; they are handled in exactly
5446 the same way as exceptions raised from an object's
5547 \method {__del__()} method.
48+
49+ Weak references are hashable if the \var {object} is hashable. They
50+ will maintain their hash value even after the \var {object} was
51+ deleted. If \function {hash()} is called the first time only after
52+ the \var {object} was deleted, the call will raise
53+ \exception {TypeError}.
54+
55+ Weak references support test for equality, but not ordering. If the
56+ \var {object} is still alive, to references are equal if the objects
57+ are equal (regardless of the \var {callback}). If the \var {object}
58+ has been deleted, they are equal iff they are identical.
59+
5660\end {funcdesc }
5761
58- \begin {funcdesc }{mapping}{\optional {dict}}
62+ \begin {funcdesc }{mapping}{\optional {dict\optional {, weakkeys=0} }}
5963 Return a weak dictionary. If \var {dict} is given and not
6064 \code {None}, the new dictionary will contain the items contained in
6165 \var {dict}. The values from \var {dict} must be weakly referencable;
6266 if any values which would be inserted into the new mapping are not
6367 weakly referencable, \exception {TypeError} will be raised and the
6468 new mapping will be empty.
69+
70+ If the \var {weakkeys} argument is not given or zero, the values in
71+ the dictionary are weak. That means the entries in the dictionary
72+ will be discarded when no strong reference to the value exists
73+ anymore.
74+
75+ If the \var {weakkeys} argument is nonzero, the keys in the
76+ dictionary are weak, i.e. the entry in the dictionary is discarded
77+ when the last strong reference to the key is discarded.
6578\end {funcdesc }
6679
6780\begin {funcdesc }{proxy}{object\optional {, callback}}
@@ -87,9 +100,16 @@ \section{\module{weakref} ---
87100 \var {object}.
88101\end {funcdesc }
89102
90- \begin {classdesc }{WeakDictionary}{\optional {dict}}
91- The class of the mapping objects returned by \function {mapping()}.
92- This can be used for subclassing the implementation if needed.
103+ \begin {classdesc }{WeakKeyDictionary}{\optional {dict}}
104+ The class of the mapping objects returned by \function {mapping()}
105+ when \var {weakkeys} is true. This can be used for subclassing the
106+ implementation if needed.
107+ \end {classdesc }
108+
109+ \begin {classdesc }{WeakValueDictionary}{\optional {dict}}
110+ The class of the mapping objects returned by \function {mapping()}
111+ when \var {weakkeys} if false. This can be used for subclassing the
112+ implementation if needed.
93113\end {classdesc }
94114
95115\begin {datadesc }{ReferenceType}
@@ -187,8 +207,8 @@ \subsection{Weak References in Extension Types
187207typedef struct {
188208 PyObject_HEAD
189209 PyClassObject *in_class; /* The class object */
190- PyObject *in_dict; /* A dictionary */
191- PyObject *in_weakreflist; /* List of weak references */
210+ PyObject *in_dict; /* A dictionary */
211+ PyObject *in_weakreflist; /* List of weak references */
192212} PyInstanceObject;
193213\end {verbatim }
194214
0 commit comments