@@ -118,6 +118,18 @@ def iterkeys(self):
118118 def __iter__ (self ):
119119 return self .data .iterkeys ()
120120
121+ def itervaluerefs (self ):
122+ """Return an iterator that yields the weak references to the values.
123+
124+ The references are not guaranteed to be 'live' at the time
125+ they are used, so the result of calling the references needs
126+ to be checked before being used. This can be used to avoid
127+ creating references that will cause the garbage collector to
128+ keep the values around longer than needed.
129+
130+ """
131+ return self .data .itervalues ()
132+
121133 def itervalues (self ):
122134 for wr in self .data .itervalues ():
123135 obj = wr ()
@@ -162,6 +174,18 @@ def update(self, dict=None, **kwargs):
162174 if len (kwargs ):
163175 self .update (kwargs )
164176
177+ def valuerefs (self ):
178+ """Return a list of weak references to the values.
179+
180+ The references are not guaranteed to be 'live' at the time
181+ they are used, so the result of calling the references needs
182+ to be checked before being used. This can be used to avoid
183+ creating references that will cause the garbage collector to
184+ keep the values around longer than needed.
185+
186+ """
187+ return self .data .values ()
188+
165189 def values (self ):
166190 L = []
167191 for wr in self .data .values ():
@@ -263,6 +287,18 @@ def iteritems(self):
263287 if key is not None :
264288 yield key , value
265289
290+ def iterkeyrefs (self ):
291+ """Return an iterator that yields the weak references to the keys.
292+
293+ The references are not guaranteed to be 'live' at the time
294+ they are used, so the result of calling the references needs
295+ to be checked before being used. This can be used to avoid
296+ creating references that will cause the garbage collector to
297+ keep the keys around longer than needed.
298+
299+ """
300+ return self .data .iterkeys ()
301+
266302 def iterkeys (self ):
267303 for wr in self .data .iterkeys ():
268304 obj = wr ()
@@ -275,6 +311,18 @@ def __iter__(self):
275311 def itervalues (self ):
276312 return self .data .itervalues ()
277313
314+ def keyrefs (self ):
315+ """Return a list of weak references to the keys.
316+
317+ The references are not guaranteed to be 'live' at the time
318+ they are used, so the result of calling the references needs
319+ to be checked before being used. This can be used to avoid
320+ creating references that will cause the garbage collector to
321+ keep the keys around longer than needed.
322+
323+ """
324+ return self .data .keys ()
325+
278326 def keys (self ):
279327 L = []
280328 for wr in self .data .keys ():
0 commit comments