💾 Archived View for tris.fyi › pydoc › weakref captured on 2023-04-26 at 13:33:05. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

Back to module index

Go to module by name

weakref

Weak reference support for Python.

This module is an implementation of PEP 205:

https://www.python.org/dev/peps/pep-0205/

Classes

CallableProxyType

KeyedRef

Specialized reference that includes a key corresponding to the value.

    This is used in the WeakValueDictionary to avoid having to create
    a function object for each key stored in the mapping.  A shared
    callback object can use the 'key' attribute of a KeyedRef instead
    of getting a reference to the key from an enclosing scope.

    
key = <member 'key' of 'KeyedRef' objects>

ProxyType

ReferenceType

WeakKeyDictionary

 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.
    
clear(self)

  D.clear() -> None.  Remove all items from D.
copy(self)
get(self, key, default=None)
items(self)
keyrefs(self)

  Return a list of weak references to the keys.

          The references are not guaranteed to be 'live' at the time
          they are used, so the result of calling the references needs
          to be checked before being used.  This can be used to avoid
          creating references that will cause the garbage collector to
          keep the keys around longer than needed.

        
keys(self)
pop(self, key, *args)
popitem(self)
setdefault(self, key, default=None)
update(self, dict=None, /, **kwargs)
values(self)

WeakMethod


    A custom `weakref.ref` subclass which simulates a weak reference to
    a bound method, working around the lifetime problem of bound methods.
    

WeakSet

add(self, item)
clear(self)
copy(self)
difference(self, other)
difference_update(self, other)
discard(self, item)
intersection(self, other)
intersection_update(self, other)
isdisjoint(self, other)
issubset(self, other)
issuperset(self, other)
pop(self)
remove(self, item)
symmetric_difference(self, other)
symmetric_difference_update(self, other)
union(self, other)
update(self, other)

WeakValueDictionary

Mapping class that references values weakly.

    Entries in the dictionary will be discarded when no strong
    reference to the value exists anymore
    
clear(self)

  D.clear() -> None.  Remove all items from D.
copy(self)
get(self, key, default=None)
items(self)
itervaluerefs(self)

  Return an iterator that yields the weak references to the values.

          The references are not guaranteed to be 'live' at the time
          they are used, so the result of calling the references needs
          to be checked before being used.  This can be used to avoid
          creating references that will cause the garbage collector to
          keep the values around longer than needed.

        
keys(self)
pop(self, key, *args)
popitem(self)
setdefault(self, key, default=None)
update(self, other=None, /, **kwargs)
valuerefs(self)

  Return a list of weak references to the values.

          The references are not guaranteed to be 'live' at the time
          they are used, so the result of calling the references needs
          to be checked before being used.  This can be used to avoid
          creating references that will cause the garbage collector to
          keep the values around longer than needed.

        
values(self)

finalize

Class for finalization of weakrefable objects

    finalize(obj, func, *args, **kwargs) returns a callable finalizer
    object which will be called when obj is garbage collected. The
    first time the finalizer is called it evaluates func(*arg, **kwargs)
    and returns the result. After this the finalizer is dead, and
    calling it just returns None.

    When the program exits any remaining finalizers for which the
    atexit attribute is true will be run in reverse order of creation.
    By default atexit is true.
    
detach(self)

  If alive then mark as dead and return (obj, func, args, kwargs);
          otherwise return None
peek(self)

  If alive then return (obj, func, args, kwargs);
          otherwise return None
alive = <property object at 0x7f75e3aaa3e0>
  Whether finalizer is alive
atexit = <property object at 0x7f75e3aaa4d0>
  Whether finalizer should be called at exit

ReferenceType

Functions

getweakrefcount

getweakrefcount(object, /)

  Return the number of weak references to 'object'.

getweakrefs

getweakrefs(...)

  getweakrefs(object) -- return a list of all weak reference objects
  that point to 'object'.

proxy

proxy(...)

  proxy(object[, callback]) -- create a proxy object that weakly
  references 'object'.  'callback', if given, is called with a
  reference to the proxy when 'object' is about to be finalized.

Other members

ProxyTypes = (<class 'weakref.ProxyType'>, <class 'weakref.CallableProxyType'>)

Modules

itertools

sys