pydispatch.utils

Function checks

isfunction(obj: object) → bool[source]

Return whether obj is a Python function.

Important

Callers using the old m keyword must use obj instead.

Changed in version 0.3.0: Renamed the m parameter to obj.

WeakMethodContainer class

class WeakMethodContainer(other=(), /, **kw)[source]

Container to store weak references to callbacks

Instance methods are stored using the underlying function object and the instance id (using id(obj)) as the key (a two-tuple) and the object itself as the value. This ensures proper weak referencing.

Functions are stored using the string “function” and the id of the function as the key (a two-tuple).

add_method(callback, **kwargs)[source]

Add an instance method or function

Parameters:

callback – The instance method or function to store

Important

Callers using the old m keyword must use callback instead.

Changed in version 0.3.0: Renamed the m parameter to callback.

del_instance(obj)[source]

Remove any stored instance methods that belong to an object

Parameters:

obj – The instance object to remove

del_method(callback)[source]

Remove an instance method or function if it exists

Parameters:

callback – The instance method or function to remove

Important

Callers using the old m keyword must use callback instead.

Changed in version 0.3.0: Renamed the m parameter to callback.

iter_instances()[source]

Iterate over the stored objects

Yields:

wrkey – The two-tuple key used to store the object obj: The instance or function object

iter_methods()[source]

Iterate over stored functions and instance methods

Yields:

Instance methods or function objects

InformativeWVDict class

class InformativeWVDict(**kwargs)[source]

Bases: WeakValueDictionary

A WeakValueDictionary providing a callback for deletion

Keyword Arguments:

del_callback – A callback function that will be called when an item is either deleted or dereferenced. It will be called with the key as the only argument.

EmissionHoldLock class

class EmissionHoldLock(event_instance)[source]

Bases: object

Context manager used for pydispatch.dispatch.Dispatcher.emission_lock()

Supports use as a context manager used in with statements and an asynchronous context manager when used in async with statements.

Parameters:

event_instance – The Event instance associated with the lock

event_instance

The Event instance associated with the lock

last_event

The positional and keyword arguments from the event’s last emission as a two-tuple. If no events were triggered while the lock was held, None.

held

The internal state of the lock

Type:

bool

async release_async()[source]

Release the current loop’s lock if held and release the emission hold.