asyncutils.properties¶
Asynchronous descriptors, mimicking property and optionally applying a lock.
Classes¶
A property with asynchronous getters, setters and deleters. |
|
Queue set and delete operations, and complete them in order only when a get is called. |
|
Module Contents¶
- class asyncutils.properties.AsyncPropertyBase[T, R][source]¶
Bases:
abc.ABCA property with asynchronous getters, setters and deleters.
Create a new async property with getterfget, setterfsetand deleterfdel.If the getter is not provided, return a partial decorator instead. In that overload, none of the accessors are to be passed.doc, if passed, will be the docstring of the property in the form of the__doc__attribute. Otherwise, an attempt is made tofind it on the getter.strictdefaults toTrue, and controls whether performing an operation that invokes an unset accessor is allowed. If it isFalse, setters and deleters are also allowed to return something other thanNone.If the property has no getter (only possible with explicitfget=Noneand at least one offsetandfdelpassed, which is rare),accessing the attribute on instances would return the property itself ifstrict=Falseand raise anAttributeErrorotherwise.IfhideisTrue(defaultFalse), accessing the attribute on the class it is defined in would raiseAttributeErroras ifthe property didn’t exist.Subclasses must define_wrap_aw(), and are allowed to override_setup()and_repr_helper(). Nothing else is customizable.- __get__(instance: R, owner: type[R] | None = ..., /) Self | types.CoroutineType[Any, Any, T][source]¶
- __get__(instance: None, owner: type, /) Self
- classmethod __init_subclass__(
- /,
- *,
- lock_factory: collections.abc.Callable[[],
- asyncutils._internal.types.AsyncContextManager[Any]]=...,
- **k: object,
lock_factory, a callable that returns a new per-instance async context manager, is required for immediate subclasses.
- __reduce__() str[source]¶
Return the qualified name of this property for pickling. Hidden properties cannot be pickled.
- static _repr_helper(
- accessor: collections.abc.Callable[Concatenate[R, Ellipsis], collections.abc.Awaitable[T | None]] | None,
- /,
Called by the implementation of
__repr__sequentially with each accessor as argument.
- _setup(
- fget: collections.abc.Callable[[R], collections.abc.Awaitable[T]],
- /,
- fset: collections.abc.Callable[[R, T], collections.abc.Awaitable[None]] | None = ...,
- fdel: collections.abc.Callable[[R], collections.abc.Awaitable[None]] | None = ...,
- *,
- doc: str | None = ...,
- strict: bool = ...,
- hide: bool = ...,
Set the necessary attributes on the property; called by
__new__().
- abstractmethod _wrap_aw[X](aw: collections.abc.Awaitable[X], /) collections.abc.Awaitable[X][source]¶
Return an awaitable resolving to the result of an awaitable, limited to those returned by the setter or deleter. This can be a coroutine, a future, a task or anything else, and affects the strategy used to handle assignments and deletions which must return synchronously but run in the background.
- 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.
- __module__: str | None¶
The module this property is defined in, determined by the function it decorates.
- property fdel: collections.abc.Callable[[R], collections.abc.Awaitable[None]] | None¶
The deleter function for this property, or
Noneif it doesn’t exist.
- property fget: collections.abc.Callable[[R], collections.abc.Awaitable[T]] | None¶
The getter function for this property, or
Noneif it doesn’t exist.
- property fset: collections.abc.Callable[[R, T], collections.abc.Awaitable[None]] | None¶
The setter function for this property, or
Noneif it doesn’t exist.
- class asyncutils.properties.ConcurrentAsyncProperty[T, R][source]¶
Bases:
AsyncPropertyBase[T,R]Allow set and delete operations to run concurrently once the operations are called, without any guarantee on the order ofexecution.The setters and deleters can be implemented acquire a writer lock and the getter the corresponding reader lock fromrwlockswith its lock policies that provide fluent decorator interfaces. Note, however, that the accessordecorators must be outermost because they turn callables into properties.Create a new async property with getterfget, setterfsetand deleterfdel.If the getter is not provided, return a partial decorator instead. In that overload, none of the accessors are to be passed.doc, if passed, will be the docstring of the property in the form of the__doc__attribute. Otherwise, an attempt is made tofind it on the getter.strictdefaults toTrue, and controls whether performing an operation that invokes an unset accessor is allowed. If it isFalse, setters and deleters are also allowed to return something other thanNone.If the property has no getter (only possible with explicitfget=Noneand at least one offsetandfdelpassed, which is rare),accessing the attribute on instances would return the property itself ifstrict=Falseand raise anAttributeErrorotherwise.IfhideisTrue(defaultFalse), accessing the attribute on the class it is defined in would raiseAttributeErroras ifthe property didn’t exist.Subclasses must define_wrap_aw(), and are allowed to override_setup()and_repr_helper(). Nothing else is customizable.- _wrap_aw[X](aw: collections.abc.Awaitable[X], /) asyncio.Task[X]¶
Return a task for the awaitable returned by the setter or deleter.
- class asyncutils.properties.LazyAsyncProperty[T, R][source]¶
Bases:
AsyncPropertyBase[T,R]Queue set and delete operations, and complete them in order only when a get is called.
Create a new async property with getterfget, setterfsetand deleterfdel.If the getter is not provided, return a partial decorator instead. In that overload, none of the accessors are to be passed.doc, if passed, will be the docstring of the property in the form of the__doc__attribute. Otherwise, an attempt is made tofind it on the getter.strictdefaults toTrue, and controls whether performing an operation that invokes an unset accessor is allowed. If it isFalse, setters and deleters are also allowed to return something other thanNone.If the property has no getter (only possible with explicitfget=Noneand at least one offsetandfdelpassed, which is rare),accessing the attribute on instances would return the property itself ifstrict=Falseand raise anAttributeErrorotherwise.IfhideisTrue(defaultFalse), accessing the attribute on the class it is defined in would raiseAttributeErroras ifthe property didn’t exist.Subclasses must define_wrap_aw(), and are allowed to override_setup()and_repr_helper(). Nothing else is customizable.- _wrap_aw[X](aw: collections.abc.Awaitable[X], /) types.CoroutineType[Any, Any, X]¶
Wrap the awaitable in a coroutine, run lazily.
- class asyncutils.properties.RWLockedAsyncProperty[T, R][source]¶
Bases:
ConcurrentAsyncProperty[T,R]Allow set and delete operations to run concurrently once the operations are called, without any guarantee on the order ofexecution.The setters and deleters can be implemented acquire a writer lock and the getter the corresponding reader lock fromrwlockswith its lock policies that provide fluent decorator interfaces. Note, however, that the accessordecorators must be outermost because they turn callables into properties.Create a new async property with getterfget, setterfsetand deleterfdel.If the getter is not provided, return a partial decorator instead. In that overload, none of the accessors are to be passed.doc, if passed, will be the docstring of the property in the form of the__doc__attribute. Otherwise, an attempt is made tofind it on the getter.strictdefaults toTrue, and controls whether performing an operation that invokes an unset accessor is allowed. If it isFalse, setters and deleters are also allowed to return something other thanNone.If the property has no getter (only possible with explicitfget=Noneand at least one offsetandfdelpassed, which is rare),accessing the attribute on instances would return the property itself ifstrict=Falseand raise anAttributeErrorotherwise.IfhideisTrue(defaultFalse), accessing the attribute on the class it is defined in would raiseAttributeErroras ifthe property didn’t exist.Subclasses must define_wrap_aw(), and are allowed to override_setup()and_repr_helper(). Nothing else is customizable.- static _repr_helper(v: collections.abc.Callable[Ellipsis, collections.abc.Awaitable[Any]] | None, /) str¶
Called by the implementation of
__repr__sequentially with each accessor as argument.
- _setup(
- f: collections.abc.Callable[[R], collections.abc.Awaitable[T]],
- /,
- fset: collections.abc.Callable[[R, T], collections.abc.Awaitable[None]] | None = None,
- fdel: collections.abc.Callable[[R], collections.abc.Awaitable[None]] | None = None,
- *,
- policy: type[asyncutils.RWLock] = ...,
- **k: Any,
Set the necessary attributes on the property; called by
__new__().