omlish 0.0.0.dev383__py3-none-any.whl → 0.0.0.dev385__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 +15 -0
- omlish/lang/maysync_.py +27 -0
- omlish/lite/args.py +7 -0
- omlish/lite/maysync.py +74 -0
- {omlish-0.0.0.dev383.dist-info → omlish-0.0.0.dev385.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev383.dist-info → omlish-0.0.0.dev385.dist-info}/RECORD +11 -9
- {omlish-0.0.0.dev383.dist-info → omlish-0.0.0.dev385.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev383.dist-info → omlish-0.0.0.dev385.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev383.dist-info → omlish-0.0.0.dev385.dist-info}/licenses/LICENSE +0 -0
- {omlish-0.0.0.dev383.dist-info → omlish-0.0.0.dev385.dist-info}/top_level.txt +0 -0
omlish/__about__.py
CHANGED
omlish/lang/__init__.py
CHANGED
@@ -250,6 +250,11 @@ from .iterables import ( # noqa
|
|
250
250
|
take,
|
251
251
|
)
|
252
252
|
|
253
|
+
from .maysync_ import ( # noqa
|
254
|
+
a_maysync_wrap,
|
255
|
+
maysync_wrap,
|
256
|
+
)
|
257
|
+
|
253
258
|
from .objects import ( # noqa
|
254
259
|
Identity,
|
255
260
|
SimpleProxy,
|
@@ -384,6 +389,16 @@ from ..lite.maybes import ( # noqa
|
|
384
389
|
Maybe,
|
385
390
|
)
|
386
391
|
|
392
|
+
from ..lite.maysync import ( # noqa
|
393
|
+
MaysyncFn,
|
394
|
+
MaysyncGen,
|
395
|
+
MaysyncOp,
|
396
|
+
MaysyncRunnable,
|
397
|
+
a_maysync,
|
398
|
+
maysync,
|
399
|
+
maysync_op,
|
400
|
+
)
|
401
|
+
|
387
402
|
empty = Maybe.empty
|
388
403
|
just = Maybe.just
|
389
404
|
|
omlish/lang/maysync_.py
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
import functools
|
2
|
+
import typing as ta
|
3
|
+
|
4
|
+
from ..lite.maysync import MaysyncGen
|
5
|
+
from ..lite.maysync import a_maysync
|
6
|
+
from ..lite.maysync import maysync
|
7
|
+
|
8
|
+
|
9
|
+
T = ta.TypeVar('T')
|
10
|
+
P = ta.ParamSpec('P')
|
11
|
+
|
12
|
+
|
13
|
+
##
|
14
|
+
|
15
|
+
|
16
|
+
def maysync_wrap(fn: ta.Callable[P, MaysyncGen[T]]) -> ta.Callable[P, T]:
|
17
|
+
@functools.wraps(fn)
|
18
|
+
def inner(*args, **kwargs):
|
19
|
+
return maysync(fn, *args, **kwargs)
|
20
|
+
return inner
|
21
|
+
|
22
|
+
|
23
|
+
def a_maysync_wrap(fn: ta.Callable[P, MaysyncGen[T]]) -> ta.Callable[P, ta.Awaitable[T]]:
|
24
|
+
@functools.wraps(fn)
|
25
|
+
async def inner(*args, **kwargs):
|
26
|
+
return await a_maysync(fn, *args, **kwargs)
|
27
|
+
return inner
|
omlish/lite/args.py
CHANGED
@@ -34,3 +34,10 @@ class Args:
|
|
34
34
|
|
35
35
|
def __call__(self, fn: ta.Callable[..., T]) -> T:
|
36
36
|
return fn(*self.args, **self.kwargs)
|
37
|
+
|
38
|
+
@staticmethod
|
39
|
+
def call(fn: ta.Callable[..., T], args: ta.Optional['Args']) -> T:
|
40
|
+
if args is not None:
|
41
|
+
return args(fn)
|
42
|
+
else:
|
43
|
+
return fn()
|
omlish/lite/maysync.py
ADDED
@@ -0,0 +1,74 @@
|
|
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)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
omlish/.manifests.json,sha256=aT8yZ-Zh-9wfHl5Ym5ouiWC1i0cy7Q7RlhzavB6VLPI,8587
|
2
|
-
omlish/__about__.py,sha256=
|
2
|
+
omlish/__about__.py,sha256=gGXdPVFaQw7agfdw7XyBUlbDyInzFNShpr6vgLJpZ_4,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=hLwhj82Yo-1n-jR9LGEH4I6wKXloD2QtPxSM7IqNlGU,6843
|
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,6 +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/maysync_.py,sha256=yvm-xnlgiw-IT4TPlJpQFu1ddgey_76n6YEE45qTm2Y,615
|
438
439
|
omlish/lang/objects.py,sha256=ZsibJwNp1EXorbaObm9TlCNtuuM65snCmVb7H4_llqI,6116
|
439
440
|
omlish/lang/outcomes.py,sha256=0PqxoKaGbBXU9UYZ6AE2QSq94Z-gFDt6wYdp0KomNQw,8712
|
440
441
|
omlish/lang/overrides.py,sha256=IBzK6ljfLX6TLgIyKTSjhqTLcuKRkQNVtEOnBLS4nuA,2095
|
@@ -465,7 +466,7 @@ omlish/lifecycles/manager.py,sha256=92s1IH_gDP25PM5tFuPMP2hD_6s5fPi_VzZiDS5549g,
|
|
465
466
|
omlish/lifecycles/states.py,sha256=6gTdY3hn7-1sJ60lA3GeMx5RVKvXtFBBXE4KEjoO1Hs,1297
|
466
467
|
omlish/lifecycles/transitions.py,sha256=3IFdWGtAeoy3XRlIyW7yCKV4e4Iof9ytkqklGMRFYQs,1944
|
467
468
|
omlish/lite/__init__.py,sha256=cyZEpGob7XjU8DohyNxVe5CQRk4CQ5vrHL42OdhQb8w,148
|
468
|
-
omlish/lite/args.py,sha256=
|
469
|
+
omlish/lite/args.py,sha256=226ah28AjJKwG9X5dV6bxbuce0UF87MsonjHXh0eLtg,924
|
469
470
|
omlish/lite/cached.py,sha256=O7ozcoDNFm1Hg2wtpHEqYSp_i_nCLNOP6Ueq_Uk-7mU,1300
|
470
471
|
omlish/lite/check.py,sha256=ytCkwZoKfOlJqylL-AGm8C2WfsWJd2q3kFbnZCzX3_M,13844
|
471
472
|
omlish/lite/configs.py,sha256=4-1uVxo-aNV7vMKa7PVNhM610eejG1WepB42-Dw2xQI,914
|
@@ -477,6 +478,7 @@ omlish/lite/json.py,sha256=m0Ce9eqUZG23-H7-oOp8n1sf4fzno5vtK4AK_4Vc-Mg,706
|
|
477
478
|
omlish/lite/logs.py,sha256=CWFG0NKGhqNeEgryF5atN2gkPYbUdTINEw_s1phbINM,51
|
478
479
|
omlish/lite/marshal.py,sha256=JD_8ox5-yeIo7MZ6iipCdiVxx33So52M02AtvFlRGC8,20392
|
479
480
|
omlish/lite/maybes.py,sha256=0p_fzb6yiOjEpvMKaQ53Q6CH1VPW1or7v7Lt1JIKcgM,4359
|
481
|
+
omlish/lite/maysync.py,sha256=dwiJE5y8h1nBnrYsfuaxITGpik0RlhpAF8qpba_Z-1g,1537
|
480
482
|
omlish/lite/pycharm.py,sha256=FRHGcCDo42UzZXqNwW_DkhI-6kb_CmJKPiQ8F6mYkLA,1174
|
481
483
|
omlish/lite/reflect.py,sha256=pzOY2PPuHH0omdtglkN6DheXDrGopdL3PtTJnejyLFU,2189
|
482
484
|
omlish/lite/reprs.py,sha256=Tiqf_ciD8FfS0ury7FcJ5G21yY342fW0vPacYlb8EO4,2014
|
@@ -891,9 +893,9 @@ omlish/typedvalues/marshal.py,sha256=AtBz7Jq-BfW8vwM7HSxSpR85JAXmxK2T0xDblmm1HI0
|
|
891
893
|
omlish/typedvalues/of_.py,sha256=UXkxSj504WI2UrFlqdZJbu2hyDwBhL7XVrc2qdR02GQ,1309
|
892
894
|
omlish/typedvalues/reflect.py,sha256=PAvKW6T4cW7u--iX80w3HWwZUS3SmIZ2_lQjT65uAyk,1026
|
893
895
|
omlish/typedvalues/values.py,sha256=ym46I-q2QJ_6l4UlERqv3yj87R-kp8nCKMRph0xQ3UA,1307
|
894
|
-
omlish-0.0.0.
|
895
|
-
omlish-0.0.0.
|
896
|
-
omlish-0.0.0.
|
897
|
-
omlish-0.0.0.
|
898
|
-
omlish-0.0.0.
|
899
|
-
omlish-0.0.0.
|
896
|
+
omlish-0.0.0.dev385.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
|
897
|
+
omlish-0.0.0.dev385.dist-info/METADATA,sha256=qKow8_sBnq26OYo6-C1MdgsrfUGCGAOlcVLMUE87lvo,18825
|
898
|
+
omlish-0.0.0.dev385.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
899
|
+
omlish-0.0.0.dev385.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
|
900
|
+
omlish-0.0.0.dev385.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
|
901
|
+
omlish-0.0.0.dev385.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|