PyDocs

Nav

Data Types

WeakKeyDictionary

weakref

class (source)
  • WeakKeyDictionary([dict])
Mapping class that references keys weakly.

Entries in the dictionary will be discarded when there is no
longer a strong reference to the key. This can be used to
associate additional data with an object owned by other parts of
an application without adding attributes to those objects. This
can be especially useful with objects that override attribute
accesses.
Changed in 3.9
  • 3.9: Added support for | and |= operators, as specified in PEP 584.
Members of WeakKeyDictionary

k

keyrefs
Return a list of weak references to the keys.
1 Example
>>> class T(str): pass
...
>>> k1, k2 = T(), T()
>>> d = weakref.WeakKeyDictionary()
>>> d[k1] = 1   # d = {k1: 1}
>>> d[k2] = 2   # d = {k1: 2}
>>> del k1      # d = {}
from the Python docs
See Also
No see-alsos for weakref/WeakKeyDictionary
0 Notes
No notes for WeakKeyDictionary