On this page
weakref.WeakSet
Prev: weakref.WeakMethod | Up: weakref | Next: weakref.WeakValueDictionary
Rel: weakref.CallableProxyType, weakref.finalize, weakref.getweakrefcount, weakref.getweakrefs
Ref: docs.python.org — weakref.WeakSet
Tags: #public #python3 #stdlib #weakref
Import
import weakref
from weakref import WeakSet
Signature & Overview
weakref.WeakSet(data=None)
weakref.WeakSet class.
Methods & Attributes
WeakSet.add(self, item)—WeakSet.addmethod/property.WeakSet.clear(self)—WeakSet.clearmethod/property.WeakSet.copy(self)—WeakSet.copymethod/property.WeakSet.difference(self, other)—WeakSet.differencemethod/property.WeakSet.difference_update(self, other)—WeakSet.difference_updatemethod/property.WeakSet.discard(self, item)—WeakSet.discardmethod/property.WeakSet.intersection(self, other)—WeakSet.intersectionmethod/property.WeakSet.intersection_update(self, other)—WeakSet.intersection_updatemethod/property.WeakSet.isdisjoint(self, other)—WeakSet.isdisjointmethod/property.WeakSet.issubset(self, other)—WeakSet.issubsetmethod/property.WeakSet.issuperset(self, other)—WeakSet.issupersetmethod/property.WeakSet.pop(self)—WeakSet.popmethod/property.WeakSet.remove(self, item)—WeakSet.removemethod/property.WeakSet.symmetric_difference(self, other)—WeakSet.symmetric_differencemethod/property.WeakSet.symmetric_difference_update(self, other)—WeakSet.symmetric_difference_updatemethod/property.WeakSet.union(self, other)—WeakSet.unionmethod/property.WeakSet.update(self, other)—WeakSet.updatemethod/property.
Usage
import weakref
class Item: pass
i = Item()
seen = weakref.WeakSet([i])
assert i in seen
del i
assert len(seen) == 0
Gotchas
- Tracks live instances automatically without keeping them alive.
REPL Inspect
from weakref import WeakSet
help(WeakSet)
Linked from
Related notes
- tuts/python3/stdlib_module/weakref/WeakMethod Linked here; links to this page; shared tags: #stdlib, #weakref
- tuts/python3/stdlib_module/weakref/WeakValueDictionary Linked here; links to this page; shared tags: #stdlib, #weakref
- tuts/python3/stdlib_module/weakref Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/weakref/CallableProxyType Linked here; shared tags: #stdlib, #weakref
- tuts/python3/stdlib_module/weakref/finalize Linked here; shared tags: #stdlib, #weakref
- tuts/python3/stdlib_module/weakref/getweakrefcount Linked here; shared tags: #stdlib, #weakref
- tuts/python3/stdlib_module/weakref/getweakrefs Linked here; shared tags: #stdlib, #weakref
- tuts/python3/stdlib_module/weakref/proxy shared tags: #stdlib, #weakref
- tuts/python3/stdlib_module/weakref/ProxyType shared tags: #stdlib, #weakref
- tuts/python3/stdlib_module/weakref/ref shared tags: #stdlib, #weakref