omlish 0.0.0.dev411__py3-none-any.whl → 0.0.0.dev413__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 CHANGED
@@ -1,5 +1,5 @@
1
- __version__ = '0.0.0.dev411'
2
- __revision__ = 'ab397888a161157384b42de969a8c743c5a2c4b6'
1
+ __version__ = '0.0.0.dev413'
2
+ __revision__ = '3a75442fb3c6056a588c83a888a2f2792d35a3ab'
3
3
 
4
4
 
5
5
  #
@@ -105,7 +105,7 @@ class Project(ProjectBase):
105
105
 
106
106
  'apsw ~= 3.50',
107
107
 
108
- 'sqlean.py ~= 3.49',
108
+ 'sqlean.py ~= 3.50',
109
109
 
110
110
  'duckdb ~= 1.3',
111
111
  ],
omlish/asyncs/bridge.py CHANGED
@@ -70,7 +70,7 @@ def trivial_s_to_a(fn):
70
70
 
71
71
  def trivial_a_to_s(fn):
72
72
  def inner(*args, **kwargs):
73
- return lang.sync_await(fn, *args, **kwargs)
73
+ return lang.sync_await(fn(*args, **kwargs))
74
74
  return inner
75
75
 
76
76
 
omlish/lang/__init__.py CHANGED
@@ -171,6 +171,8 @@ from .descriptors import ( # noqa
171
171
  decorator,
172
172
  is_method_descriptor,
173
173
  item_property,
174
+ unwrap_callable,
175
+ unwrap_callable_with_partials,
174
176
  unwrap_func,
175
177
  unwrap_func_with_partials,
176
178
  unwrap_method_descriptors,
@@ -280,12 +282,11 @@ from .lazyglobals import ( # noqa
280
282
  )
281
283
 
282
284
  from .maysyncs import ( # noqa
283
- MaysyncFn,
284
- MaysyncGeneratorFn,
285
-
285
+ make_maysync_fn,
286
+ make_maysync_generator_fn,
286
287
  make_maysync,
288
+
287
289
  make_maysync_from_sync,
288
- maysync,
289
290
  )
290
291
 
291
292
  from .objects import ( # noqa
@@ -426,12 +427,23 @@ empty = Maybe.empty
426
427
  just = Maybe.just
427
428
 
428
429
  from ..lite.maysyncs import ( # noqa
430
+ mark_maysync,
431
+ is_maysync,
432
+
433
+ AnyMaysyncFn,
434
+
435
+ MaywaitableAlreadyConsumedError,
436
+ AnyMaywaitable,
437
+
438
+ MaysyncFn,
429
439
  Maywaitable,
440
+
441
+ MaysyncGeneratorFn,
430
442
  MaysyncGenerator,
431
443
 
432
- Maysync_,
433
- MaysyncFn_,
434
- MaysyncGeneratorFn_,
444
+ is_running_maysync,
445
+
446
+ run_maysync,
435
447
  )
436
448
 
437
449
  from ..lite.reprs import ( # noqa
omlish/lang/asyncs.py CHANGED
@@ -2,29 +2,24 @@ import typing as ta
2
2
 
3
3
 
4
4
  T = ta.TypeVar('T')
5
- P = ta.ParamSpec('P')
6
5
 
7
6
 
8
7
  ##
9
8
 
10
9
 
11
10
  async def async_list(
12
- fn: ta.Callable[P, ta.AsyncIterator[T]],
13
- *args: P.args,
14
- **kwargs: P.kwargs,
11
+ ai: ta.AsyncIterable[T],
15
12
  ) -> list[T]:
16
13
  """Simply eagerly reads the full contents of a function call returning an async iterator."""
17
14
 
18
- return [v async for v in fn(*args, **kwargs)]
15
+ return [v async for v in ai]
19
16
 
20
17
 
21
18
  ##
22
19
 
23
20
 
24
21
  def sync_await(
25
- fn: ta.Callable[P, ta.Awaitable[T]],
26
- *args: P.args,
27
- **kwargs: P.kwargs,
22
+ aw: ta.Awaitable[T],
28
23
  ) -> T:
29
24
  """
30
25
  Allows for the synchronous execution of async functions which will never actually *externally* await anything. These
@@ -37,7 +32,7 @@ def sync_await(
37
32
  async def gate():
38
33
  nonlocal ret
39
34
 
40
- ret = await fn(*args, **kwargs)
35
+ ret = await aw
41
36
 
42
37
  cr = gate()
43
38
  try:
@@ -56,9 +51,7 @@ def sync_await(
56
51
 
57
52
 
58
53
  def sync_async_list(
59
- fn: ta.Callable[P, ta.AsyncIterator[T]],
60
- *args: P.args,
61
- **kwargs: P.kwargs,
54
+ ai: ta.AsyncIterable[T],
62
55
  ) -> list[T]:
63
56
  """
64
57
  Uses `sync_await` to synchronously read the full contents of a function call returning an async iterator, given that
@@ -70,9 +63,9 @@ def sync_async_list(
70
63
  async def inner():
71
64
  nonlocal lst
72
65
 
73
- lst = [v async for v in fn(*args, **kwargs)]
66
+ lst = [v async for v in ai]
74
67
 
75
- sync_await(inner)
68
+ sync_await(inner())
76
69
 
77
70
  if not isinstance(lst, list):
78
71
  raise TypeError(lst)
@@ -92,6 +92,20 @@ def unwrap_func(fn: ta.Any) -> ta.Any:
92
92
  ##
93
93
 
94
94
 
95
+ def unwrap_callable_with_partials(obj: ta.Any) -> tuple[ta.Any, list[functools.partial]]:
96
+ if isinstance(obj, type):
97
+ obj = obj.__call__
98
+ return unwrap_func_with_partials(obj)
99
+
100
+
101
+ def unwrap_callable(obj: ta.Any) -> ta.Any:
102
+ uw, _ = unwrap_callable_with_partials(obj)
103
+ return uw
104
+
105
+
106
+ ##
107
+
108
+
95
109
  def update_wrapper(
96
110
  wrapper: T,
97
111
  wrapped: ta.Any,
omlish/lang/maysyncs.py CHANGED
@@ -1,11 +1,8 @@
1
1
  import typing as ta
2
2
 
3
- from ..lite.maysyncs import MaysyncGenerator
4
- from ..lite.maysyncs import Maywaitable
3
+ from ..lite.maysyncs import MaysyncFn
4
+ from ..lite.maysyncs import MaysyncGeneratorFn
5
5
  from ..lite.maysyncs import make_maysync as _make_maysync
6
- from ..lite.maysyncs import maysync as _maysync
7
- from ..lite.maysyncs import maysync_fn as _maysync_fn
8
- from ..lite.maysyncs import maysync_generator_fn as _maysync_generator_fn
9
6
  from .functions import as_async
10
7
 
11
8
 
@@ -15,61 +12,61 @@ I = ta.TypeVar('I')
15
12
 
16
13
  P = ta.ParamSpec('P')
17
14
 
18
- MaysyncFn: ta.TypeAlias = ta.Callable[P, Maywaitable[T]]
19
- MaysyncGeneratorFn: ta.TypeAlias = ta.Callable[P, MaysyncGenerator[O, I]]
20
-
21
15
 
22
16
  ##
23
17
 
24
18
 
25
- def make_maysync(
19
+ def make_maysync_fn(
26
20
  s: ta.Callable[P, T],
27
21
  a: ta.Callable[P, ta.Awaitable[T]],
28
- ) -> MaysyncFn[P, T]:
29
- return ta.cast('MaysyncFn[P, T]', _make_maysync(
30
- s,
31
- a,
32
- ))
33
-
34
-
35
- def make_maysync_from_sync(
36
- s: ta.Callable[P, T],
37
- a: ta.Callable[P, ta.Awaitable[T]] | None = None,
38
- ) -> MaysyncFn[P, T]:
39
- return ta.cast('MaysyncFn[P, T]', _make_maysync(
40
- s,
41
- a if a is not None else as_async(s),
42
- ))
22
+ ) -> ta.Callable[P, ta.Awaitable[T]]:
23
+ """Constructs a MaysyncFn from a (sync, async) function pair."""
43
24
 
25
+ return MaysyncFn(s, a)
44
26
 
45
- ##
46
27
 
28
+ def make_maysync_generator_fn(
29
+ s: ta.Callable[P, ta.Generator[O, I]],
30
+ a: ta.Callable[P, ta.AsyncGenerator[O, I]],
31
+ ) -> ta.Callable[P, ta.AsyncGenerator[O, I]]:
32
+ """Constructs a MaysyncGeneratorFn from a (sync, async) generator function pair."""
47
33
 
48
- def maysync_fn(
49
- m: ta.Callable[P, ta.Awaitable[T]],
50
- ) -> MaysyncFn[P, T]:
51
- return ta.cast('MaysyncFn[P, T]', _maysync_fn(m))
52
-
53
-
54
- def maysync_generator_fn(
55
- m: ta.Callable[P, ta.AsyncGenerator[O, I]],
56
- ) -> MaysyncGeneratorFn[P, O, I]:
57
- return ta.cast('MaysyncGeneratorFn[P, O, I]', _maysync_generator_fn(m))
34
+ return MaysyncGeneratorFn(s, a)
58
35
 
59
36
 
60
37
  @ta.overload
61
- def maysync(
62
- m: ta.Callable[P, ta.Awaitable[T]],
63
- ) -> MaysyncFn[P, T]:
38
+ def make_maysync(
39
+ s: ta.Callable[P, T],
40
+ a: ta.Callable[P, ta.Awaitable[T]],
41
+ ) -> ta.Callable[P, ta.Awaitable[T]]:
64
42
  ...
65
43
 
66
44
 
67
45
  @ta.overload
68
- def maysync(
69
- m: ta.Callable[P, ta.AsyncGenerator[O, I]],
70
- ) -> MaysyncGeneratorFn[P, O, I]:
46
+ def make_maysync(
47
+ s: ta.Callable[P, ta.Generator[O, I]],
48
+ a: ta.Callable[P, ta.AsyncGenerator[O, I]],
49
+ ) -> ta.Callable[P, ta.AsyncGenerator[O, I]]:
71
50
  ...
72
51
 
73
52
 
74
- def maysync(m):
75
- return _maysync(m)
53
+ def make_maysync(s, a):
54
+ """
55
+ Constructs a MaysyncFn or MaysyncGeneratorFn from a (sync, async) function pair, using `inspect.isasyncgenfunction`
56
+ to determine the type.
57
+ """
58
+
59
+ return _make_maysync(s, a)
60
+
61
+
62
+ ##
63
+
64
+
65
+ def make_maysync_from_sync(
66
+ s: ta.Callable[P, T],
67
+ a: ta.Callable[P, ta.Awaitable[T]] | None = None,
68
+ ) -> ta.Callable[P, ta.Awaitable[T]]:
69
+ return _make_maysync(
70
+ s,
71
+ a if a is not None else as_async(s),
72
+ )