On this page
  1. weakref.WeakKeyDictionary
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

weakref.WeakKeyDictionary

Prev: weakref.ReferenceType | Up: weakref | Next: weakref.WeakMethod
Rel: weakref.CallableProxyType, weakref.finalize, weakref.getweakrefcount, weakref.getweakrefs
Ref: docs.python.org — weakref.WeakKeyDictionary
Tags: #public #python3 #stdlib #weakref


Import

import weakref
from weakref import WeakKeyDictionary

Signature & Overview

weakref.WeakKeyDictionary(dict=None)

Mapping class that references keys weakly.

Methods & Attributes

Usage

import weakref

class Node: pass
n = Node()
meta = weakref.WeakKeyDictionary({n: 'root'})
assert meta[n] == 'root'
del n
assert len(meta) == 0

Gotchas

REPL Inspect

from weakref import WeakKeyDictionary
help(WeakKeyDictionary)

Linked from

Related notes