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

weakref.WeakValueDictionary

Prev: weakref.WeakSet | Up: weakref
Rel: weakref.CallableProxyType, weakref.finalize, weakref.getweakrefcount, weakref.getweakrefs
Ref: docs.python.org — weakref.WeakValueDictionary
Tags: #public #python3 #stdlib #weakref


Import

import weakref
from weakref import WeakValueDictionary

Signature & Overview

weakref.WeakValueDictionary(other=(), /, **kw)

Mapping class that references values weakly.

Methods & Attributes

Usage

import weakref

class CacheObj: pass
obj = CacheObj()
cache = weakref.WeakValueDictionary({'k': obj})
assert cache['k'] is obj
del obj
assert 'k' not in cache

Gotchas

REPL Inspect

from weakref import WeakValueDictionary
help(WeakValueDictionary)

Linked from

Related notes