From 746fa0134f3201ac60fb22f4ae64810a0bec6544 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Fri, 17 Jan 2020 14:15:57 +0100 Subject: [PATCH] add tiramisu/asyncinit.py file --- tiramisu/asyncinit.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tiramisu/asyncinit.py diff --git a/tiramisu/asyncinit.py b/tiramisu/asyncinit.py new file mode 100644 index 0000000..b73183b --- /dev/null +++ b/tiramisu/asyncinit.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019 Team tiramisu (see AUTHORS for all contributors) +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see . +# +# largely inspired by https://github.com/kchmck/pyasyncinit +# ____________________________________________________________ +from functools import wraps + + +def asyncinit(obj): + @wraps(obj.__new__) + async def new(cls, *args, **kwargs): + instance = object.__new__(cls) # (cls, *args, **kwargs) + await instance.__init__(*args, **kwargs) + return instance + obj.__new__ = new + return obj