omlish 0.0.0.dev386__py3-none-any.whl → 0.0.0.dev387__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- omlish/__about__.py +2 -2
- omlish/lang/__init__.py +8 -17
- omlish/lang/maysyncs.py +41 -0
- omlish/lite/args.py +5 -0
- omlish/lite/maysyncs.py +184 -0
- {omlish-0.0.0.dev386.dist-info → omlish-0.0.0.dev387.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev386.dist-info → omlish-0.0.0.dev387.dist-info}/RECORD +11 -11
- omlish/lang/maysync_.py +0 -53
- omlish/lite/maysync.py +0 -74
- {omlish-0.0.0.dev386.dist-info → omlish-0.0.0.dev387.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev386.dist-info → omlish-0.0.0.dev387.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev386.dist-info → omlish-0.0.0.dev387.dist-info}/licenses/LICENSE +0 -0
- {omlish-0.0.0.dev386.dist-info → omlish-0.0.0.dev387.dist-info}/top_level.txt +0 -0
omlish/__about__.py
CHANGED
omlish/lang/__init__.py
CHANGED
@@ -250,13 +250,12 @@ from .iterables import ( # noqa
|
|
250
250
|
take,
|
251
251
|
)
|
252
252
|
|
253
|
-
from .
|
254
|
-
|
253
|
+
from .maysyncs import ( # noqa
|
254
|
+
MaysyncableP,
|
255
255
|
|
256
|
-
|
256
|
+
make_maysync,
|
257
257
|
|
258
|
-
|
259
|
-
a_maysync_wrap,
|
258
|
+
maysync,
|
260
259
|
)
|
261
260
|
|
262
261
|
from .objects import ( # noqa
|
@@ -393,21 +392,13 @@ from ..lite.maybes import ( # noqa
|
|
393
392
|
Maybe,
|
394
393
|
)
|
395
394
|
|
396
|
-
from ..lite.maysync import ( # noqa
|
397
|
-
MaysyncGen,
|
398
|
-
MaysyncFn,
|
399
|
-
|
400
|
-
MaysyncOp,
|
401
|
-
|
402
|
-
maysync,
|
403
|
-
a_maysync,
|
404
|
-
|
405
|
-
MaysyncRunnable,
|
406
|
-
)
|
407
|
-
|
408
395
|
empty = Maybe.empty
|
409
396
|
just = Maybe.just
|
410
397
|
|
398
|
+
from ..lite.maysyncs import ( # noqa
|
399
|
+
Maysyncable,
|
400
|
+
)
|
401
|
+
|
411
402
|
from ..lite.reprs import ( # noqa
|
412
403
|
AttrRepr,
|
413
404
|
attr_repr,
|
omlish/lang/maysyncs.py
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
import typing as ta
|
2
|
+
|
3
|
+
from ..lite.maysyncs import make_maysync as _make_maysync
|
4
|
+
from ..lite.maysyncs import maysync as _maysync
|
5
|
+
|
6
|
+
|
7
|
+
T_co = ta.TypeVar('T_co', covariant=True)
|
8
|
+
P = ta.ParamSpec('P')
|
9
|
+
|
10
|
+
|
11
|
+
##
|
12
|
+
|
13
|
+
|
14
|
+
class MaysyncableP(ta.Protocol[P, T_co]):
|
15
|
+
@property
|
16
|
+
def s(self) -> ta.Callable[P, T_co]:
|
17
|
+
...
|
18
|
+
|
19
|
+
@property
|
20
|
+
def a(self) -> ta.Callable[P, ta.Awaitable[T_co]]:
|
21
|
+
...
|
22
|
+
|
23
|
+
@property
|
24
|
+
def m(self) -> ta.Callable[P, ta.Awaitable[T_co]]:
|
25
|
+
...
|
26
|
+
|
27
|
+
|
28
|
+
def make_maysync(
|
29
|
+
s: ta.Callable[P, T_co],
|
30
|
+
a: ta.Callable[P, ta.Awaitable[T_co]],
|
31
|
+
) -> MaysyncableP[P, T_co]:
|
32
|
+
return ta.cast('MaysyncableP[P, T_co]', _make_maysync(
|
33
|
+
s,
|
34
|
+
a,
|
35
|
+
))
|
36
|
+
|
37
|
+
|
38
|
+
def maysync(m: ta.Callable[P, ta.Awaitable[T_co]]) -> MaysyncableP[P, T_co]:
|
39
|
+
return ta.cast('MaysyncableP[P, T_co]', _maysync(
|
40
|
+
m,
|
41
|
+
))
|
omlish/lite/args.py
CHANGED
omlish/lite/maysyncs.py
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
# ruff: noqa: UP045
|
2
|
+
# @omlish-lite
|
3
|
+
import abc
|
4
|
+
import dataclasses as dc
|
5
|
+
import functools
|
6
|
+
import typing as ta
|
7
|
+
|
8
|
+
from .args import Args
|
9
|
+
from .check import check
|
10
|
+
|
11
|
+
|
12
|
+
T = ta.TypeVar('T')
|
13
|
+
|
14
|
+
_MaysyncGen = ta.Generator['_MaysyncOp', ta.Any, T] # ta.TypeAlias
|
15
|
+
|
16
|
+
|
17
|
+
##
|
18
|
+
|
19
|
+
|
20
|
+
@dc.dataclass(frozen=True, eq=False)
|
21
|
+
class Maysyncable(abc.ABC, ta.Generic[T]):
|
22
|
+
@abc.abstractmethod
|
23
|
+
def s(self, *args: ta.Any, **kwargs: ta.Any) -> T:
|
24
|
+
raise NotImplementedError
|
25
|
+
|
26
|
+
@abc.abstractmethod
|
27
|
+
def a(self, *args: ta.Any, **kwargs: ta.Any) -> ta.Awaitable[T]:
|
28
|
+
raise NotImplementedError
|
29
|
+
|
30
|
+
@ta.final
|
31
|
+
def m(self, *args: ta.Any, **kwargs: ta.Any) -> ta.Awaitable[T]:
|
32
|
+
return _MaysyncFuture(_MaysyncOp(self, Args(*args, **kwargs)))
|
33
|
+
|
34
|
+
|
35
|
+
##
|
36
|
+
|
37
|
+
|
38
|
+
@dc.dataclass(frozen=True, eq=False)
|
39
|
+
class _FnMaysyncable(Maysyncable[T]):
|
40
|
+
s: ta.Callable[..., T]
|
41
|
+
a: ta.Callable[..., ta.Awaitable[T]]
|
42
|
+
|
43
|
+
def __post_init__(self) -> None:
|
44
|
+
check.not_none(self.s)
|
45
|
+
check.not_none(self.a)
|
46
|
+
|
47
|
+
def __init_subclass__(cls, **kwargs):
|
48
|
+
raise TypeError
|
49
|
+
|
50
|
+
|
51
|
+
_FnMaysyncable.__abstractmethods__ = frozenset()
|
52
|
+
|
53
|
+
|
54
|
+
def make_maysync(
|
55
|
+
s: ta.Callable[..., T],
|
56
|
+
a: ta.Callable[..., ta.Awaitable[T]],
|
57
|
+
) -> Maysyncable[T]:
|
58
|
+
return _FnMaysyncable(
|
59
|
+
s,
|
60
|
+
a,
|
61
|
+
)
|
62
|
+
|
63
|
+
|
64
|
+
##
|
65
|
+
|
66
|
+
|
67
|
+
@dc.dataclass(frozen=True, eq=False)
|
68
|
+
class _MgMaysyncable(Maysyncable[T]):
|
69
|
+
mg: ta.Callable[..., _MaysyncGen[T]]
|
70
|
+
|
71
|
+
def __init_subclass__(cls, **kwargs):
|
72
|
+
raise TypeError
|
73
|
+
|
74
|
+
def s(self, *args: ta.Any, **kwargs: ta.Any) -> T:
|
75
|
+
g = self.mg(*args, **kwargs)
|
76
|
+
|
77
|
+
i: ta.Any = None
|
78
|
+
e: ta.Any = None
|
79
|
+
|
80
|
+
while True:
|
81
|
+
try:
|
82
|
+
if e is not None:
|
83
|
+
o = g.throw(e)
|
84
|
+
else:
|
85
|
+
o = g.send(i)
|
86
|
+
except StopIteration as ex:
|
87
|
+
return ex.value
|
88
|
+
|
89
|
+
i = None
|
90
|
+
e = None
|
91
|
+
|
92
|
+
mo = check.isinstance(o, _MaysyncOp)
|
93
|
+
try:
|
94
|
+
i = mo.a(mo.mx.s)
|
95
|
+
except BaseException as ex: # noqa
|
96
|
+
e = ex
|
97
|
+
|
98
|
+
async def a(self, *args: ta.Any, **kwargs: ta.Any) -> T:
|
99
|
+
g = self.mg(*args, **kwargs)
|
100
|
+
|
101
|
+
i: ta.Any = None
|
102
|
+
e: ta.Any = None
|
103
|
+
|
104
|
+
while True:
|
105
|
+
try:
|
106
|
+
if e is not None:
|
107
|
+
o = g.throw(e)
|
108
|
+
else:
|
109
|
+
o = g.send(i)
|
110
|
+
except StopIteration as ex:
|
111
|
+
return ex.value
|
112
|
+
|
113
|
+
i = None
|
114
|
+
e = None
|
115
|
+
|
116
|
+
mo = check.isinstance(o, _MaysyncOp)
|
117
|
+
try:
|
118
|
+
i = await mo.a(mo.mx.a)
|
119
|
+
except BaseException as ex: # noqa
|
120
|
+
e = ex
|
121
|
+
|
122
|
+
|
123
|
+
def maysync(m: ta.Callable[..., ta.Awaitable[T]]) -> Maysyncable[T]:
|
124
|
+
@functools.wraps(m)
|
125
|
+
def mg_fn(*args, **kwargs):
|
126
|
+
a = m(*args, **kwargs).__await__()
|
127
|
+
|
128
|
+
try:
|
129
|
+
g = iter(a)
|
130
|
+
try:
|
131
|
+
while True:
|
132
|
+
try:
|
133
|
+
o = g.send(None)
|
134
|
+
except StopIteration as e:
|
135
|
+
return e.value
|
136
|
+
|
137
|
+
f = check.isinstance(o, _MaysyncFuture)
|
138
|
+
if not f.done:
|
139
|
+
try:
|
140
|
+
f.result = yield f.op
|
141
|
+
except BaseException as e: # noqa
|
142
|
+
f.error = e
|
143
|
+
f.done = True
|
144
|
+
|
145
|
+
finally:
|
146
|
+
g.close()
|
147
|
+
|
148
|
+
finally:
|
149
|
+
a.close()
|
150
|
+
|
151
|
+
return _MgMaysyncable(mg_fn)
|
152
|
+
|
153
|
+
|
154
|
+
##
|
155
|
+
|
156
|
+
|
157
|
+
@dc.dataclass(frozen=True, eq=False)
|
158
|
+
class _MaysyncOp:
|
159
|
+
mx: Maysyncable
|
160
|
+
a: Args
|
161
|
+
|
162
|
+
def __init_subclass__(cls, **kwargs):
|
163
|
+
raise TypeError
|
164
|
+
|
165
|
+
|
166
|
+
##
|
167
|
+
|
168
|
+
|
169
|
+
@dc.dataclass(eq=False)
|
170
|
+
class _MaysyncFuture(ta.Generic[T]):
|
171
|
+
op: _MaysyncOp
|
172
|
+
|
173
|
+
done: bool = False
|
174
|
+
error: ta.Optional[BaseException] = None
|
175
|
+
result: ta.Optional[T] = None
|
176
|
+
|
177
|
+
def __await__(self):
|
178
|
+
if not self.done:
|
179
|
+
yield self
|
180
|
+
if not self.done:
|
181
|
+
raise RuntimeError("await wasn't used with event future")
|
182
|
+
if self.error is not None:
|
183
|
+
raise self.error
|
184
|
+
return self.result
|
@@ -1,5 +1,5 @@
|
|
1
1
|
omlish/.manifests.json,sha256=aT8yZ-Zh-9wfHl5Ym5ouiWC1i0cy7Q7RlhzavB6VLPI,8587
|
2
|
-
omlish/__about__.py,sha256=
|
2
|
+
omlish/__about__.py,sha256=1JXviS8ZhIT4Fi_DnSuQcb5P_uSRCpOk-GoDo5m01hs,3543
|
3
3
|
omlish/__init__.py,sha256=SsyiITTuK0v74XpKV8dqNaCmjOlan1JZKrHQv5rWKPA,253
|
4
4
|
omlish/c3.py,sha256=rer-TPOFDU6fYq_AWio_AmA-ckZ8JDY5shIzQ_yXfzA,8414
|
5
5
|
omlish/cached.py,sha256=MLap_p0rdGoDIMVhXVHm1tsbcWobJF0OanoodV03Ju8,542
|
@@ -420,7 +420,7 @@ omlish/iterators/iterators.py,sha256=RxW35yQ5ed8vBQ22IqpDXFx-i5JiLQdp7-pkMZXhJJ8
|
|
420
420
|
omlish/iterators/recipes.py,sha256=wOwOZg-zWG9Zc3wcAxJFSe2rtavVBYwZOfG09qYEx_4,472
|
421
421
|
omlish/iterators/tools.py,sha256=M16LXrJhMdsz5ea2qH0vws30ZvhQuQSCVFSLpRf_gTg,2096
|
422
422
|
omlish/iterators/unique.py,sha256=Nw0pSaNEcHAkve0ugfLPvJcirDOn9ECyC5wIL8JlJKI,1395
|
423
|
-
omlish/lang/__init__.py,sha256=
|
423
|
+
omlish/lang/__init__.py,sha256=gNF9vQCR1y1qICSaTfh-eR5d8H_kCjuHwxlGMbjUc9I,6763
|
424
424
|
omlish/lang/attrs.py,sha256=zFiVuGVOq88x45464T_LxDa-ZEq_RD9zJLq2zeVEBDc,5105
|
425
425
|
omlish/lang/casing.py,sha256=cFUlbDdXLhwnWwcYx4qnM5c4zGX7hIRUfcjiZbxUD28,4636
|
426
426
|
omlish/lang/clsdct.py,sha256=HAGIvBSbCefzRjXriwYSBLO7QHKRv2UsE78jixOb-fA,1828
|
@@ -435,7 +435,7 @@ omlish/lang/functions.py,sha256=aLdxhmqG0Pj9tBgsKdoCu_q15r82WIkNqDDSPQU19L8,5689
|
|
435
435
|
omlish/lang/generators.py,sha256=a4D5HU_mySs2T2z3xCmE_s3t4QJkj0YRrK4-hhpGd0A,5197
|
436
436
|
omlish/lang/imports.py,sha256=y9W9Y-d_cQ35QCLuSIPoa6vnEqSErFCz8b-34IH128U,10552
|
437
437
|
omlish/lang/iterables.py,sha256=y1SX2Co3VsOeX2wlfFF7K3rwLvF7Dtre7VY6EpfwAwA,3338
|
438
|
-
omlish/lang/
|
438
|
+
omlish/lang/maysyncs.py,sha256=QXI_I7_yxgRugXYfH8drmLIdcEUmhPrM6hDJwxjpqT4,840
|
439
439
|
omlish/lang/objects.py,sha256=ZsibJwNp1EXorbaObm9TlCNtuuM65snCmVb7H4_llqI,6116
|
440
440
|
omlish/lang/outcomes.py,sha256=0PqxoKaGbBXU9UYZ6AE2QSq94Z-gFDt6wYdp0KomNQw,8712
|
441
441
|
omlish/lang/overrides.py,sha256=IBzK6ljfLX6TLgIyKTSjhqTLcuKRkQNVtEOnBLS4nuA,2095
|
@@ -466,7 +466,7 @@ omlish/lifecycles/manager.py,sha256=92s1IH_gDP25PM5tFuPMP2hD_6s5fPi_VzZiDS5549g,
|
|
466
466
|
omlish/lifecycles/states.py,sha256=6gTdY3hn7-1sJ60lA3GeMx5RVKvXtFBBXE4KEjoO1Hs,1297
|
467
467
|
omlish/lifecycles/transitions.py,sha256=3IFdWGtAeoy3XRlIyW7yCKV4e4Iof9ytkqklGMRFYQs,1944
|
468
468
|
omlish/lite/__init__.py,sha256=cyZEpGob7XjU8DohyNxVe5CQRk4CQ5vrHL42OdhQb8w,148
|
469
|
-
omlish/lite/args.py,sha256=
|
469
|
+
omlish/lite/args.py,sha256=ILJXAiN3KjIoJwY42aKpYPngUdxHIy9ssVIExFVz3fE,978
|
470
470
|
omlish/lite/cached.py,sha256=O7ozcoDNFm1Hg2wtpHEqYSp_i_nCLNOP6Ueq_Uk-7mU,1300
|
471
471
|
omlish/lite/check.py,sha256=ytCkwZoKfOlJqylL-AGm8C2WfsWJd2q3kFbnZCzX3_M,13844
|
472
472
|
omlish/lite/configs.py,sha256=4-1uVxo-aNV7vMKa7PVNhM610eejG1WepB42-Dw2xQI,914
|
@@ -478,7 +478,7 @@ omlish/lite/json.py,sha256=m0Ce9eqUZG23-H7-oOp8n1sf4fzno5vtK4AK_4Vc-Mg,706
|
|
478
478
|
omlish/lite/logs.py,sha256=CWFG0NKGhqNeEgryF5atN2gkPYbUdTINEw_s1phbINM,51
|
479
479
|
omlish/lite/marshal.py,sha256=JD_8ox5-yeIo7MZ6iipCdiVxx33So52M02AtvFlRGC8,20392
|
480
480
|
omlish/lite/maybes.py,sha256=0p_fzb6yiOjEpvMKaQ53Q6CH1VPW1or7v7Lt1JIKcgM,4359
|
481
|
-
omlish/lite/
|
481
|
+
omlish/lite/maysyncs.py,sha256=VyzjbjG7GiQGq1GIFyldrH7R6D4HlpkKGx-PSkbnlW0,4115
|
482
482
|
omlish/lite/pycharm.py,sha256=FRHGcCDo42UzZXqNwW_DkhI-6kb_CmJKPiQ8F6mYkLA,1174
|
483
483
|
omlish/lite/reflect.py,sha256=pzOY2PPuHH0omdtglkN6DheXDrGopdL3PtTJnejyLFU,2189
|
484
484
|
omlish/lite/reprs.py,sha256=Tiqf_ciD8FfS0ury7FcJ5G21yY342fW0vPacYlb8EO4,2014
|
@@ -894,9 +894,9 @@ omlish/typedvalues/marshal.py,sha256=AtBz7Jq-BfW8vwM7HSxSpR85JAXmxK2T0xDblmm1HI0
|
|
894
894
|
omlish/typedvalues/of_.py,sha256=UXkxSj504WI2UrFlqdZJbu2hyDwBhL7XVrc2qdR02GQ,1309
|
895
895
|
omlish/typedvalues/reflect.py,sha256=PAvKW6T4cW7u--iX80w3HWwZUS3SmIZ2_lQjT65uAyk,1026
|
896
896
|
omlish/typedvalues/values.py,sha256=ym46I-q2QJ_6l4UlERqv3yj87R-kp8nCKMRph0xQ3UA,1307
|
897
|
-
omlish-0.0.0.
|
898
|
-
omlish-0.0.0.
|
899
|
-
omlish-0.0.0.
|
900
|
-
omlish-0.0.0.
|
901
|
-
omlish-0.0.0.
|
902
|
-
omlish-0.0.0.
|
897
|
+
omlish-0.0.0.dev387.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
|
898
|
+
omlish-0.0.0.dev387.dist-info/METADATA,sha256=zhW4aKIRiJ7u6QaBhvG0lt3oNjw4lcjik82VF-mp_SA,18825
|
899
|
+
omlish-0.0.0.dev387.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
900
|
+
omlish-0.0.0.dev387.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
|
901
|
+
omlish-0.0.0.dev387.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
|
902
|
+
omlish-0.0.0.dev387.dist-info/RECORD,,
|
omlish/lang/maysync_.py
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
import functools
|
2
|
-
import typing as ta
|
3
|
-
|
4
|
-
from ..lite.maysync import MaysyncGen
|
5
|
-
from ..lite.maysync import MaysyncOp
|
6
|
-
from ..lite.maysync import a_maysync
|
7
|
-
from ..lite.maysync import maysync
|
8
|
-
|
9
|
-
|
10
|
-
T = ta.TypeVar('T')
|
11
|
-
P = ta.ParamSpec('P')
|
12
|
-
|
13
|
-
|
14
|
-
##
|
15
|
-
|
16
|
-
|
17
|
-
def maysync_op(
|
18
|
-
fn: ta.Callable[P, T],
|
19
|
-
a_fn: ta.Callable[P, ta.Awaitable[T]],
|
20
|
-
) -> MaysyncOp[T]:
|
21
|
-
return MaysyncOp(
|
22
|
-
fn,
|
23
|
-
a_fn,
|
24
|
-
)
|
25
|
-
|
26
|
-
|
27
|
-
##
|
28
|
-
|
29
|
-
|
30
|
-
def maysync_yield(
|
31
|
-
fn: ta.Callable[P, T],
|
32
|
-
a_fn: ta.Callable[P, ta.Awaitable[T]],
|
33
|
-
) -> ta.Callable[P, ta.Generator[ta.Any, ta.Any, T]]:
|
34
|
-
def inner(*args, **kwargs):
|
35
|
-
return (yield MaysyncOp(fn, a_fn)(*args, **kwargs))
|
36
|
-
return inner
|
37
|
-
|
38
|
-
|
39
|
-
##
|
40
|
-
|
41
|
-
|
42
|
-
def maysync_wrap(fn: ta.Callable[P, MaysyncGen[T]]) -> ta.Callable[P, T]:
|
43
|
-
@functools.wraps(fn)
|
44
|
-
def inner(*args, **kwargs):
|
45
|
-
return maysync(fn, *args, **kwargs)
|
46
|
-
return inner
|
47
|
-
|
48
|
-
|
49
|
-
def a_maysync_wrap(fn: ta.Callable[P, MaysyncGen[T]]) -> ta.Callable[P, ta.Awaitable[T]]:
|
50
|
-
@functools.wraps(fn)
|
51
|
-
async def inner(*args, **kwargs):
|
52
|
-
return await a_maysync(fn, *args, **kwargs)
|
53
|
-
return inner
|
omlish/lite/maysync.py
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# ruff: noqa: UP045
|
2
|
-
import abc
|
3
|
-
import dataclasses as dc
|
4
|
-
import typing as ta
|
5
|
-
|
6
|
-
from .args import Args
|
7
|
-
|
8
|
-
|
9
|
-
T = ta.TypeVar('T')
|
10
|
-
|
11
|
-
|
12
|
-
MaysyncGen = ta.Generator['MaysyncOp', ta.Any, T] # ta.TypeAlias
|
13
|
-
MaysyncFn = ta.Callable[..., MaysyncGen[T]] # ta.TypeAlias
|
14
|
-
|
15
|
-
|
16
|
-
##
|
17
|
-
|
18
|
-
|
19
|
-
@dc.dataclass(frozen=True)
|
20
|
-
class MaysyncOp(ta.Generic[T]):
|
21
|
-
fn: ta.Callable[..., T]
|
22
|
-
a_fn: ta.Callable[..., ta.Awaitable[T]]
|
23
|
-
|
24
|
-
args: ta.Optional[Args] = None
|
25
|
-
|
26
|
-
def __call__(self, *args: ta.Any, **kwargs: ta.Any) -> 'MaysyncOp[T]':
|
27
|
-
if self.args is not None:
|
28
|
-
raise RuntimeError('Args already bound')
|
29
|
-
return dc.replace(self, args=Args(*args, **kwargs))
|
30
|
-
|
31
|
-
|
32
|
-
maysync_op = MaysyncOp
|
33
|
-
|
34
|
-
|
35
|
-
##
|
36
|
-
|
37
|
-
|
38
|
-
def maysync(fn: MaysyncFn[T], *args: ta.Any, **kwargs: ta.Any) -> T:
|
39
|
-
g = fn(*args, **kwargs)
|
40
|
-
i = None
|
41
|
-
while True:
|
42
|
-
try:
|
43
|
-
o = g.send(i)
|
44
|
-
except StopIteration as e:
|
45
|
-
return e.value
|
46
|
-
i = Args.call(o.fn, o.args)
|
47
|
-
|
48
|
-
|
49
|
-
async def a_maysync(fn: MaysyncFn[T], *args: ta.Any, **kwargs: ta.Any) -> T:
|
50
|
-
g = fn(*args, **kwargs)
|
51
|
-
i = None
|
52
|
-
while True:
|
53
|
-
try:
|
54
|
-
o = g.send(i)
|
55
|
-
except StopIteration as e:
|
56
|
-
return e.value
|
57
|
-
i = await Args.call(o.a_fn, o.args)
|
58
|
-
|
59
|
-
|
60
|
-
##
|
61
|
-
|
62
|
-
|
63
|
-
class MaysyncRunnable(abc.ABC, ta.Generic[T]):
|
64
|
-
@abc.abstractmethod
|
65
|
-
def m_run(self) -> MaysyncGen[T]:
|
66
|
-
raise NotImplementedError
|
67
|
-
|
68
|
-
@ta.final
|
69
|
-
def run(self) -> T:
|
70
|
-
return maysync(self.m_run)
|
71
|
-
|
72
|
-
@ta.final
|
73
|
-
async def a_run(self) -> T:
|
74
|
-
return await a_maysync(self.m_run)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|