asyncutils.properties#

Asynchronous descriptors, mimicking property and optionally applying a lock.

Classes#

AsyncLockProperty

A property with asynchronous getters, setters and deleters running synchronously via event loop scheduling.

AsyncProperty

A property with asynchronous getters, setters and deleters running synchronously via event loop scheduling.

coercedmethod

Interpret any callable as a regular function in a class body so that access on instance returns something like a bound method.

Module Contents#

class asyncutils.properties.AsyncLockProperty[T, R: _collections_abc.Hashable][source]#

Bases: AsyncProperty[T, R]

A property with asynchronous getters, setters and deleters running synchronously via event loop scheduling.

static _new_lock[L: asyncutils._internal.types.AsyncLockLike[Any]](_: R, *, lock_impl: type[L]) L[source]#
static _new_lock(_: R) asyncio.locks.Lock

Default way to create a new lock for the given object. The implementation should not cache the locks for each instance, since that is done by this class already.

get_lock(obj: R) asyncutils._internal.types.AsyncLockLike[Any][source]#

Get the lock for the given object, applying a cache that unfortunately requires the object to be hashable and weakly referencable.

class asyncutils.properties.AsyncProperty[T, R][source]#

A property with asynchronous getters, setters and deleters running synchronously via event loop scheduling.

__delete__(instance: R, /) None[source]#
__get__(instance: R, owner: type[R] | None = ..., /) Self | T[source]#
__get__(instance: None, owner: type, /) Self
__set__(instance: R, value: T, /) None[source]#
__set_name__(typ: type[R], name: str, /) None[source]#
deleter(fdel: _collections_abc.Callable[[R], _collections_abc.Awaitable[None]], /) Self[source]#

Return another async property with the given function as the deleter.

getter(fget: _collections_abc.Callable[[R], _collections_abc.Awaitable[T]], /) Self[source]#

Return another async property with the given function as the getter.

setter(fset: _collections_abc.Callable[[R, T], _collections_abc.Awaitable[None]], /) Self[source]#

Return another async property with the given function as the setter.

property fdel: _collections_abc.Callable[[R], _collections_abc.Awaitable[None]] | None#

The deleter function for this property, or None if it doesn’t exist.

property fget: _collections_abc.Callable[[R], _collections_abc.Awaitable[T]] | None#

The getter function for this property, or None if it doesn’t exist.

property fset: _collections_abc.Callable[[R, T], _collections_abc.Awaitable[None]] | None#

The setter function for this property, or None if it doesn’t exist.

class asyncutils.properties.coercedmethod[T, R, **P](func: _collections_abc.Callable[Concatenate[R, P], T], /)[source]#

Interpret any callable as a regular function in a class body so that access on instance returns something like a bound method.

__get__(instance: R, owner: type[R] | None = ..., /) _collections_abc.Callable[P, T][source]#

Return the ‘bound method’. The descriptor itself is hidden and cannot be accessed on the class it is defined in, only instances of.

__getattr__(name: str, /) Any[source]#
__set_name__(owner: type[R], name: str, /) None[source]#