Asynchronous property setter
You can use the async-property
package: https://pypi.org/project/async-property/
Example:
from async_property import async_property
class Foo:
@async_property
async def remote_value(self):
return await get_remote_value()
f = Foo()
await f.remote_value
You can't nest a statement inside another statement; assignment is a statement, and so is await
. You could use setattr()
to set attributes in an expression:
await setattr(t, 'attrib', 3)
However, a property
wraps the setter in a way that does not support async
methods (they are not awaitable), so you are still better off with an explicit setter method.