|
15 | 15 | # You should have received a copy of the GNU Lesser General Public License
|
16 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 | 17 |
|
| 18 | +import asyncio |
18 | 19 | import importlib
|
19 | 20 |
|
20 | 21 |
|
@@ -43,6 +44,18 @@ def __init__(self, manager, attrs):
|
43 | 44 | self.__dict__["_parent_attrs"] = self.manager.parent_attrs
|
44 | 45 | self._create_managers()
|
45 | 46 |
|
| 47 | + @classmethod |
| 48 | + def create(cls, manager, attrs): |
| 49 | + if asyncio.iscoroutine(attrs): |
| 50 | + return cls._acreate(manager, attrs) |
| 51 | + else: |
| 52 | + return cls(manager, attrs) |
| 53 | + |
| 54 | + @classmethod |
| 55 | + async def _acreate(cls, manager, attrs): |
| 56 | + attrs = await attrs |
| 57 | + return cls(manager, attrs) |
| 58 | + |
46 | 59 | def __getstate__(self):
|
47 | 60 | state = self.__dict__.copy()
|
48 | 61 | module = state.pop("_module")
|
@@ -174,6 +187,18 @@ def __init__(self, manager, obj_cls, _list):
|
174 | 187 | self._obj_cls = obj_cls
|
175 | 188 | self._list = _list
|
176 | 189 |
|
| 190 | + @classmethod |
| 191 | + def create(cls, manager, obj_cls, _list): |
| 192 | + if asyncio.iscoroutine(_list): |
| 193 | + return cls._acreate(manager, obj_cls, _list) |
| 194 | + else: |
| 195 | + return cls(manager, obj_cls, _list) |
| 196 | + |
| 197 | + @classmethod |
| 198 | + async def _from_coroutine(cls, manager, obj_cls, _list): |
| 199 | + _list = await _list |
| 200 | + return cls(manager, obj_cls, _list) |
| 201 | + |
177 | 202 | def __len__(self):
|
178 | 203 | return len(self._list)
|
179 | 204 |
|
|
0 commit comments