aobject¶
-
class
privex.helpers.asyncx.
aobject
(*a, **kw)[source]¶ Inheriting this class allows you to define an async __init__.
To use async constructors, you must construct your class using
await MyClass(params)
Example:
>>> class SomeClass(aobject): ... async def __init__(self, some_param='x'): ... self.some_param = some_param ... self.example = await self.test_async() ... ... async def test_async(self): ... return "hello world" ... >>> async def main(): ... some_class = await SomeClass('testing') ... print(some_class.example) ...
Note: Some IDEs like PyCharm may complain about having async
__new__
and__init__
, but it does work with Python 3.6+.You may be able to work-around the syntax error in your sub-class by defining your
__init__
method under a different name, and then assigning__init__ = _your_real_init
much like this class does.Original source: https://stackoverflow.com/a/45364670
-
async
__init__
() Initialize self. See help(type(self)) for accurate signature.
-
async