omlish 0.0.0.dev1__py3-none-any.whl → 0.0.0.dev3__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.
Potentially problematic release.
This version of omlish might be problematic. Click here for more details.
- omlish/__about__.py +2 -3
- omlish/argparse.py +8 -8
- omlish/asyncs/__init__.py +2 -2
- omlish/asyncs/anyio.py +64 -1
- omlish/asyncs/asyncs.py +1 -3
- omlish/asyncs/futures.py +16 -15
- omlish/c3.py +5 -5
- omlish/check.py +8 -8
- omlish/collections/__init__.py +98 -63
- omlish/collections/_abc.py +2 -0
- omlish/collections/_io_abc.py +4 -2
- omlish/collections/cache/__init__.py +1 -1
- omlish/collections/cache/descriptor.py +12 -12
- omlish/collections/cache/impl.py +27 -20
- omlish/collections/cache/types.py +1 -1
- omlish/collections/coerce.py +44 -44
- omlish/collections/frozen.py +9 -9
- omlish/collections/identity.py +4 -5
- omlish/collections/mappings.py +5 -5
- omlish/collections/ordered.py +8 -8
- omlish/collections/skiplist.py +7 -7
- omlish/collections/sorted.py +4 -4
- omlish/collections/treap.py +42 -17
- omlish/collections/treapmap.py +59 -7
- omlish/collections/unmodifiable.py +25 -24
- omlish/collections/utils.py +1 -1
- omlish/configs/flattening.py +8 -7
- omlish/configs/props.py +3 -3
- omlish/dataclasses/__init__.py +1 -1
- omlish/dataclasses/impl/__init__.py +18 -0
- omlish/dataclasses/impl/api.py +15 -24
- omlish/dataclasses/impl/as_.py +4 -4
- omlish/dataclasses/impl/exceptions.py +1 -1
- omlish/dataclasses/impl/fields.py +8 -8
- omlish/dataclasses/impl/frozen.py +2 -2
- omlish/dataclasses/impl/init.py +6 -6
- omlish/dataclasses/impl/internals.py +16 -1
- omlish/dataclasses/impl/main.py +4 -4
- omlish/dataclasses/impl/metaclass.py +2 -2
- omlish/dataclasses/impl/metadata.py +1 -1
- omlish/dataclasses/impl/order.py +2 -2
- omlish/dataclasses/impl/params.py +4 -38
- omlish/dataclasses/impl/reflect.py +1 -7
- omlish/dataclasses/impl/replace.py +1 -1
- omlish/dataclasses/impl/repr.py +24 -6
- omlish/dataclasses/impl/simple.py +2 -2
- omlish/dataclasses/impl/slots.py +2 -2
- omlish/dataclasses/impl/utils.py +7 -7
- omlish/defs.py +13 -17
- omlish/diag/procfs.py +334 -0
- omlish/diag/ps.py +47 -0
- omlish/{replserver → diag/replserver}/console.py +26 -28
- omlish/{replserver → diag/replserver}/server.py +12 -12
- omlish/dispatch/dispatch.py +14 -16
- omlish/dispatch/functions.py +1 -1
- omlish/dispatch/methods.py +6 -7
- omlish/docker.py +8 -6
- omlish/dynamic.py +13 -13
- omlish/fnpairs.py +311 -0
- omlish/graphs/dot/items.py +1 -1
- omlish/graphs/trees.py +25 -31
- omlish/inject/__init__.py +7 -7
- omlish/inject/elements.py +2 -2
- omlish/inject/exceptions.py +8 -8
- omlish/inject/impl/elements.py +4 -4
- omlish/inject/impl/injector.py +6 -6
- omlish/inject/impl/inspect.py +3 -3
- omlish/inject/impl/scopes.py +9 -9
- omlish/inject/injector.py +1 -1
- omlish/inject/providers.py +2 -2
- omlish/inject/proxy.py +5 -5
- omlish/iterators.py +62 -26
- omlish/json.py +7 -6
- omlish/lang/__init__.py +172 -112
- omlish/lang/cached.py +15 -10
- omlish/lang/classes/__init__.py +35 -24
- omlish/lang/classes/abstract.py +3 -3
- omlish/lang/classes/restrict.py +14 -14
- omlish/lang/classes/simple.py +2 -2
- omlish/lang/classes/virtual.py +5 -5
- omlish/lang/clsdct.py +2 -2
- omlish/lang/cmp.py +2 -2
- omlish/lang/contextmanagers.py +31 -25
- omlish/lang/datetimes.py +1 -1
- omlish/lang/descriptors.py +51 -6
- omlish/lang/exceptions.py +2 -0
- omlish/lang/functions.py +101 -35
- omlish/lang/imports.py +25 -30
- omlish/lang/iterables.py +2 -2
- omlish/lang/maybes.py +2 -1
- omlish/lang/objects.py +17 -11
- omlish/lang/resolving.py +1 -1
- omlish/lang/strings.py +1 -1
- omlish/lang/timeouts.py +53 -0
- omlish/lang/typing.py +5 -5
- omlish/libc.py +15 -11
- omlish/logs/_abc.py +5 -1
- omlish/logs/filters.py +2 -0
- omlish/logs/formatters.py +6 -2
- omlish/logs/utils.py +1 -1
- omlish/marshal/base.py +9 -9
- omlish/marshal/dataclasses.py +2 -2
- omlish/marshal/enums.py +2 -2
- omlish/marshal/exceptions.py +1 -1
- omlish/marshal/factories.py +10 -10
- omlish/marshal/global_.py +10 -4
- omlish/marshal/iterables.py +2 -2
- omlish/marshal/mappings.py +2 -2
- omlish/marshal/objects.py +1 -2
- omlish/marshal/optionals.py +4 -4
- omlish/marshal/polymorphism.py +4 -4
- omlish/marshal/registries.py +3 -3
- omlish/marshal/standard.py +6 -6
- omlish/marshal/utils.py +3 -3
- omlish/marshal/values.py +1 -1
- omlish/math.py +9 -9
- omlish/os.py +13 -4
- omlish/reflect.py +5 -15
- omlish/sql/__init__.py +0 -0
- omlish/sql/_abc.py +65 -0
- omlish/sql/dbs.py +90 -0
- omlish/stats.py +7 -8
- omlish/term.py +1 -1
- omlish/testing/pydevd.py +30 -12
- omlish/testing/pytest/inject/__init__.py +7 -0
- omlish/testing/pytest/inject/harness.py +24 -2
- omlish/testing/pytest/plugins/__init__.py +1 -1
- omlish/testing/pytest/plugins/pydevd.py +12 -0
- omlish/testing/pytest/plugins/switches.py +3 -3
- omlish/testing/testing.py +5 -5
- omlish/text/delimit.py +3 -6
- omlish/text/parts.py +3 -3
- omlish-0.0.0.dev3.dist-info/METADATA +31 -0
- omlish-0.0.0.dev3.dist-info/RECORD +191 -0
- {omlish-0.0.0.dev1.dist-info → omlish-0.0.0.dev3.dist-info}/WHEEL +1 -1
- omlish/lang/classes/test/test_abstract.py +0 -89
- omlish/lang/classes/test/test_restrict.py +0 -71
- omlish/lang/classes/test/test_simple.py +0 -58
- omlish/lang/classes/test/test_virtual.py +0 -72
- omlish/testing/pytest/plugins/pycharm.py +0 -54
- omlish-0.0.0.dev1.dist-info/METADATA +0 -17
- omlish-0.0.0.dev1.dist-info/RECORD +0 -187
- /omlish/{lang/classes/test → diag}/__init__.py +0 -0
- /omlish/{replserver → diag/replserver}/__init__.py +0 -0
- /omlish/{replserver → diag/replserver}/__main__.py +0 -0
- {omlish-0.0.0.dev1.dist-info → omlish-0.0.0.dev3.dist-info}/LICENSE +0 -0
- {omlish-0.0.0.dev1.dist-info → omlish-0.0.0.dev3.dist-info}/top_level.txt +0 -0
omlish/__about__.py
CHANGED
omlish/argparse.py
CHANGED
|
@@ -48,7 +48,7 @@ ArgumentParser = argparse.ArgumentParser
|
|
|
48
48
|
class Arg:
|
|
49
49
|
args: ta.Sequence[ta.Any]
|
|
50
50
|
kwargs: ta.Mapping[str, ta.Any]
|
|
51
|
-
dest:
|
|
51
|
+
dest: str | None = None
|
|
52
52
|
|
|
53
53
|
def __get__(self, instance, owner=None):
|
|
54
54
|
if instance is None:
|
|
@@ -92,8 +92,8 @@ class Command:
|
|
|
92
92
|
|
|
93
93
|
def command(
|
|
94
94
|
*args: Arg,
|
|
95
|
-
name:
|
|
96
|
-
parent:
|
|
95
|
+
name: str | None = None,
|
|
96
|
+
parent: Command | None = None,
|
|
97
97
|
) -> ta.Any: # ta.Callable[[CommandFn], Command]: # FIXME
|
|
98
98
|
for arg in args:
|
|
99
99
|
check.isinstance(arg, Arg)
|
|
@@ -164,7 +164,7 @@ class _CliMeta(type):
|
|
|
164
164
|
namespace['_parser'] = parser
|
|
165
165
|
|
|
166
166
|
subparsers = parser.add_subparsers()
|
|
167
|
-
for
|
|
167
|
+
for att, obj in objs.items():
|
|
168
168
|
if isinstance(obj, Command):
|
|
169
169
|
if obj.parent is not None:
|
|
170
170
|
raise NotImplementedError
|
|
@@ -174,14 +174,14 @@ class _CliMeta(type):
|
|
|
174
174
|
cparser.set_defaults(_cmd=obj)
|
|
175
175
|
|
|
176
176
|
elif isinstance(obj, Arg):
|
|
177
|
-
if
|
|
178
|
-
akwargs = get_arg_ann_kwargs(anns[
|
|
177
|
+
if att in anns:
|
|
178
|
+
akwargs = get_arg_ann_kwargs(anns[att])
|
|
179
179
|
obj.kwargs = {**akwargs, **obj.kwargs}
|
|
180
180
|
if not obj.dest:
|
|
181
181
|
if 'dest' in obj.kwargs:
|
|
182
182
|
obj.dest = obj.kwargs['dest']
|
|
183
183
|
else:
|
|
184
|
-
obj.dest = obj.kwargs['dest'] =
|
|
184
|
+
obj.dest = obj.kwargs['dest'] = att # type: ignore
|
|
185
185
|
parser.add_argument(*obj.args, **obj.kwargs)
|
|
186
186
|
|
|
187
187
|
else:
|
|
@@ -192,7 +192,7 @@ class _CliMeta(type):
|
|
|
192
192
|
|
|
193
193
|
class Cli(metaclass=_CliMeta):
|
|
194
194
|
|
|
195
|
-
def __init__(self, argv: ta.
|
|
195
|
+
def __init__(self, argv: ta.Sequence[str] | None = None) -> None:
|
|
196
196
|
super().__init__()
|
|
197
197
|
|
|
198
198
|
self._argv = argv if argv is not None else sys.argv[1:]
|
omlish/asyncs/__init__.py
CHANGED
omlish/asyncs/anyio.py
CHANGED
|
@@ -7,10 +7,15 @@ lookit:
|
|
|
7
7
|
- https://github.com/M-o-a-T/asyncscope
|
|
8
8
|
- https://github.com/M-o-a-T/aevent
|
|
9
9
|
- https://github.com/florimondmanca/aiometer
|
|
10
|
+
- https://github.com/sanitizers/octomachinery/blob/b36c3d3d49da813ac46e361424132955a4e99ac8/octomachinery/utils/asynctools.py
|
|
10
11
|
""" # noqa
|
|
11
12
|
import typing as ta
|
|
12
13
|
|
|
13
|
-
import anyio
|
|
14
|
+
import anyio.streams.memory
|
|
15
|
+
import anyio.streams.stapled
|
|
16
|
+
|
|
17
|
+
from .. import check
|
|
18
|
+
from .. import lang
|
|
14
19
|
|
|
15
20
|
|
|
16
21
|
T = ta.TypeVar('T')
|
|
@@ -21,3 +26,61 @@ async def anyio_eof_to_empty(fn: ta.Callable[..., ta.Awaitable[T]], *args: ta.An
|
|
|
21
26
|
return await fn(*args, **kwargs)
|
|
22
27
|
except anyio.EndOfStream:
|
|
23
28
|
return b''
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def split_memory_object_streams(
|
|
32
|
+
*args: anyio.create_memory_object_stream[T],
|
|
33
|
+
) -> tuple[
|
|
34
|
+
anyio.streams.memory.MemoryObjectSendStream[T],
|
|
35
|
+
anyio.streams.memory.MemoryObjectReceiveStream[T],
|
|
36
|
+
]:
|
|
37
|
+
[tup] = args
|
|
38
|
+
return tup
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# FIXME: https://github.com/python/mypy/issues/15238
|
|
42
|
+
# FIXME: https://youtrack.jetbrains.com/issues?q=tag:%20%7BPEP%20695%7D
|
|
43
|
+
def create_memory_object_stream[T](max_buffer_size: float = 0) -> tuple[
|
|
44
|
+
anyio.streams.memory.MemoryObjectSendStream[T],
|
|
45
|
+
anyio.streams.memory.MemoryObjectReceiveStream[T],
|
|
46
|
+
]:
|
|
47
|
+
return anyio.create_memory_object_stream[T](max_buffer_size) # noqa
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def staple_memory_object_stream(
|
|
51
|
+
*args: anyio.create_memory_object_stream[T],
|
|
52
|
+
) -> anyio.streams.stapled.StapledObjectStream[T]:
|
|
53
|
+
send, receive = args
|
|
54
|
+
return anyio.streams.stapled.StapledObjectStream(
|
|
55
|
+
check.isinstance(send, anyio.streams.memory.MemoryObjectSendStream), # type: ignore
|
|
56
|
+
check.isinstance(receive, anyio.streams.memory.MemoryObjectReceiveStream), # type: ignore
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# FIXME: https://github.com/python/mypy/issues/15238
|
|
61
|
+
# FIXME: https://youtrack.jetbrains.com/issues?q=tag:%20%7BPEP%20695%7D
|
|
62
|
+
def staple_memory_object_stream2[T](max_buffer_size: float = 0) -> anyio.streams.stapled.StapledObjectStream[T]:
|
|
63
|
+
send, receive = anyio.create_memory_object_stream[T](max_buffer_size)
|
|
64
|
+
return anyio.streams.stapled.StapledObjectStream(
|
|
65
|
+
check.isinstance(send, anyio.streams.memory.MemoryObjectSendStream), # type: ignore
|
|
66
|
+
check.isinstance(receive, anyio.streams.memory.MemoryObjectReceiveStream), # type: ignore
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
async def gather(*fns: ta.Callable[..., ta.Awaitable[T]], take_first: bool = False) -> list[lang.Maybe[T]]:
|
|
71
|
+
results: list[lang.Maybe[T]] = [lang.empty()] * len(fns)
|
|
72
|
+
|
|
73
|
+
async def inner(fn, i):
|
|
74
|
+
results[i] = lang.just(await fn())
|
|
75
|
+
if take_first:
|
|
76
|
+
tg.cancel_scope.cancel()
|
|
77
|
+
|
|
78
|
+
async with anyio.create_task_group() as tg:
|
|
79
|
+
for i, fn in enumerate(fns):
|
|
80
|
+
tg.start_soon(inner, fn, i)
|
|
81
|
+
|
|
82
|
+
return results
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
async def first(*fns: ta.Callable[..., ta.Awaitable[T]], **kwargs: ta.Any) -> list[lang.Maybe[T]]:
|
|
86
|
+
return await gather(*fns, take_first=True, **kwargs)
|
omlish/asyncs/asyncs.py
CHANGED
|
@@ -26,10 +26,8 @@ def sync_await(fn: ta.Callable[..., T], *args, **kwargs) -> T:
|
|
|
26
26
|
|
|
27
27
|
cr = gate()
|
|
28
28
|
with contextlib.closing(cr):
|
|
29
|
-
|
|
29
|
+
with contextlib.suppress(StopIteration):
|
|
30
30
|
cr.send(None)
|
|
31
|
-
except StopIteration:
|
|
32
|
-
pass
|
|
33
31
|
if ret is missing or cr.cr_await is not None or cr.cr_running:
|
|
34
32
|
raise TypeError('Not terminated')
|
|
35
33
|
|
omlish/asyncs/futures.py
CHANGED
|
@@ -5,14 +5,15 @@ import typing as ta
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
T = ta.TypeVar('T')
|
|
8
|
+
P = ta.ParamSpec('P')
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
##
|
|
11
12
|
|
|
12
13
|
|
|
13
|
-
class
|
|
14
|
+
class FutureError(Exception, ta.Generic[T]):
|
|
14
15
|
|
|
15
|
-
def __init__(self, future: cf.Future, target:
|
|
16
|
+
def __init__(self, future: cf.Future, target: T | None = None) -> None:
|
|
16
17
|
super().__init__()
|
|
17
18
|
|
|
18
19
|
self._future = future
|
|
@@ -23,7 +24,7 @@ class FutureException(Exception, ta.Generic[T]):
|
|
|
23
24
|
return self._future
|
|
24
25
|
|
|
25
26
|
@property
|
|
26
|
-
def target(self) ->
|
|
27
|
+
def target(self) -> T | None:
|
|
27
28
|
return self._target
|
|
28
29
|
|
|
29
30
|
def __repr__(self) -> str:
|
|
@@ -37,15 +38,15 @@ class FutureException(Exception, ta.Generic[T]):
|
|
|
37
38
|
__str__ = __repr__
|
|
38
39
|
|
|
39
40
|
|
|
40
|
-
class
|
|
41
|
+
class FutureTimeoutError(Exception):
|
|
41
42
|
pass
|
|
42
43
|
|
|
43
44
|
|
|
44
45
|
def wait_futures(
|
|
45
46
|
futures: ta.Sequence[cf.Future],
|
|
46
47
|
*,
|
|
47
|
-
timeout_s:
|
|
48
|
-
tick_interval_s:
|
|
48
|
+
timeout_s: float = 60,
|
|
49
|
+
tick_interval_s: float = .5,
|
|
49
50
|
tick_fn: ta.Callable[..., bool] = lambda: True,
|
|
50
51
|
raise_exceptions: bool = False,
|
|
51
52
|
cancel_on_exception: bool = False,
|
|
@@ -61,14 +62,14 @@ def wait_futures(
|
|
|
61
62
|
if cancel_on_exception:
|
|
62
63
|
for cancel_fut in not_done:
|
|
63
64
|
cancel_fut.cancel()
|
|
64
|
-
raise
|
|
65
|
+
raise FutureError(fut) from fut.exception()
|
|
65
66
|
|
|
66
67
|
not_done -= done
|
|
67
68
|
if not not_done:
|
|
68
69
|
return True
|
|
69
70
|
|
|
70
71
|
if time.time() >= (start + timeout_s):
|
|
71
|
-
raise
|
|
72
|
+
raise FutureTimeoutError
|
|
72
73
|
time.sleep(tick_interval_s)
|
|
73
74
|
|
|
74
75
|
return False
|
|
@@ -78,8 +79,8 @@ def wait_dependent_futures(
|
|
|
78
79
|
executor: cf.Executor,
|
|
79
80
|
dependency_sets_by_fn: ta.Mapping[ta.Callable, ta.AbstractSet[ta.Callable]],
|
|
80
81
|
*,
|
|
81
|
-
timeout_s:
|
|
82
|
-
tick_interval_s:
|
|
82
|
+
timeout_s: float = 60,
|
|
83
|
+
tick_interval_s: float = .5,
|
|
83
84
|
tick_fn: ta.Callable[..., bool] = lambda: True,
|
|
84
85
|
) -> ta.Mapping[ta.Callable, cf.Future]:
|
|
85
86
|
for fn, deps in dependency_sets_by_fn.items():
|
|
@@ -91,7 +92,7 @@ def wait_dependent_futures(
|
|
|
91
92
|
if fn in dependency_sets_by_fn[dep]:
|
|
92
93
|
raise Exception(f'Cyclic dependencies: {fn} <-> {dep}', fn, dep)
|
|
93
94
|
|
|
94
|
-
dependent_sets_by_fn:
|
|
95
|
+
dependent_sets_by_fn: dict[ta.Callable, set[ta.Callable]] = {fn: set() for fn in dependency_sets_by_fn}
|
|
95
96
|
for fn, deps in dependency_sets_by_fn.items():
|
|
96
97
|
for dep in deps:
|
|
97
98
|
dependent_sets_by_fn[dep].add(fn)
|
|
@@ -114,7 +115,7 @@ def wait_dependent_futures(
|
|
|
114
115
|
for fut in done:
|
|
115
116
|
if fut.exception():
|
|
116
117
|
cancel()
|
|
117
|
-
raise
|
|
118
|
+
raise FutureError(fut) from fut.exception()
|
|
118
119
|
|
|
119
120
|
fn = fns_by_fut[fut]
|
|
120
121
|
for dependent_fn in dependent_sets_by_fn.get(fn, set()):
|
|
@@ -128,11 +129,11 @@ def wait_dependent_futures(
|
|
|
128
129
|
|
|
129
130
|
if time.time() >= (start + timeout_s):
|
|
130
131
|
cancel()
|
|
131
|
-
raise
|
|
132
|
+
raise FutureTimeoutError
|
|
132
133
|
|
|
133
134
|
remaining_fns = {fn: deps for fn, deps in remaining_dep_sets_by_fn.items() if deps}
|
|
134
135
|
if remaining_fns:
|
|
135
|
-
raise Exception(f
|
|
136
|
+
raise Exception(f'Unfinished fns: {remaining_fns}', remaining_fns)
|
|
136
137
|
|
|
137
138
|
futs_by_fn = {fn: fut for fut, fn in fns_by_fut.items()}
|
|
138
139
|
return futs_by_fn
|
|
@@ -147,7 +148,7 @@ class ImmediateExecutor(cf.Executor):
|
|
|
147
148
|
super().__init__()
|
|
148
149
|
self._immediate_exceptions = immediate_exceptions
|
|
149
150
|
|
|
150
|
-
def submit(self, fn, *args, **kwargs):
|
|
151
|
+
def submit(self, fn: ta.Callable[P, T], /, *args: P.args, **kwargs: P.kwargs) -> cf.Future[T]:
|
|
151
152
|
future: ta.Any = cf.Future()
|
|
152
153
|
try:
|
|
153
154
|
result = fn(*args, **kwargs)
|
omlish/c3.py
CHANGED
|
@@ -49,7 +49,7 @@ def merge(seqs: ta.MutableSequence[list[T]]) -> list[T]:
|
|
|
49
49
|
"""
|
|
50
50
|
|
|
51
51
|
result: list[T] = []
|
|
52
|
-
candidate:
|
|
52
|
+
candidate: T | None = None
|
|
53
53
|
while True:
|
|
54
54
|
seqs = [s for s in seqs if s] # purge empty sequences
|
|
55
55
|
if not seqs:
|
|
@@ -73,7 +73,7 @@ def merge(seqs: ta.MutableSequence[list[T]]) -> list[T]:
|
|
|
73
73
|
|
|
74
74
|
def mro(
|
|
75
75
|
cls: T,
|
|
76
|
-
abcs: ta.
|
|
76
|
+
abcs: ta.Sequence[T] | None = None,
|
|
77
77
|
*,
|
|
78
78
|
get_bases: ta.Callable[[T], ta.Sequence[T]] = operator.attrgetter('__bases__'),
|
|
79
79
|
is_subclass: ta.Callable[[T, T], bool] = issubclass, # type: ignore
|
|
@@ -113,9 +113,9 @@ def mro(
|
|
|
113
113
|
abstract_c3_mros = [mro(base, abcs=abcs, get_bases=get_bases, is_subclass=is_subclass) for base in abstract_bases]
|
|
114
114
|
other_c3_mros = [mro(base, abcs=abcs, get_bases=get_bases, is_subclass=is_subclass) for base in other_bases]
|
|
115
115
|
return merge(
|
|
116
|
-
[[cls]] +
|
|
116
|
+
[[cls]] + # noqa
|
|
117
117
|
explicit_c3_mros + abstract_c3_mros + other_c3_mros +
|
|
118
|
-
[explicit_bases] + [abstract_bases] + [other_bases]
|
|
118
|
+
[explicit_bases] + [abstract_bases] + [other_bases],
|
|
119
119
|
)
|
|
120
120
|
|
|
121
121
|
|
|
@@ -123,7 +123,7 @@ def compose_mro(
|
|
|
123
123
|
cls: T,
|
|
124
124
|
types: ta.Iterable[T],
|
|
125
125
|
*,
|
|
126
|
-
get_mro: ta.Callable[[T], ta.
|
|
126
|
+
get_mro: ta.Callable[[T], ta.Sequence[T] | None] = operator.attrgetter('__mro__'),
|
|
127
127
|
get_bases: ta.Callable[[T], ta.Sequence[T]] = operator.attrgetter('__bases__'),
|
|
128
128
|
is_subclass: ta.Callable[[T, T], bool] = issubclass, # type: ignore
|
|
129
129
|
get_subclasses: ta.Callable[[T], ta.Iterable[T]] = operator.methodcaller('__subclasses__'),
|
omlish/check.py
CHANGED
|
@@ -9,7 +9,7 @@ import typing as ta
|
|
|
9
9
|
T = ta.TypeVar('T')
|
|
10
10
|
SizedT = ta.TypeVar('SizedT', bound=ta.Sized)
|
|
11
11
|
|
|
12
|
-
Message =
|
|
12
|
+
Message = str | ta.Callable[..., str | None] | None
|
|
13
13
|
|
|
14
14
|
_NONE_TYPE = type(None)
|
|
15
15
|
|
|
@@ -33,7 +33,7 @@ def _raise(
|
|
|
33
33
|
default_message: str,
|
|
34
34
|
message: Message,
|
|
35
35
|
*args: ta.Any,
|
|
36
|
-
**kwargs: ta.Any
|
|
36
|
+
**kwargs: ta.Any,
|
|
37
37
|
) -> ta.NoReturn:
|
|
38
38
|
if _callable(message):
|
|
39
39
|
message = ta.cast(ta.Callable, message)(*args, **kwargs)
|
|
@@ -52,7 +52,7 @@ def _unpack_isinstance_spec(spec: ta.Any) -> tuple:
|
|
|
52
52
|
if not _isinstance(spec, tuple):
|
|
53
53
|
spec = (spec,)
|
|
54
54
|
if None in spec:
|
|
55
|
-
spec = tuple(filter(None, spec)) + (_NONE_TYPE,)
|
|
55
|
+
spec = tuple(filter(None, spec)) + (_NONE_TYPE,) # noqa
|
|
56
56
|
if ta.Any in spec:
|
|
57
57
|
spec = (object,)
|
|
58
58
|
return spec
|
|
@@ -64,7 +64,7 @@ def isinstance(v: ta.Any, spec: ta.Union[type[T], tuple], msg: Message = None) -
|
|
|
64
64
|
return v
|
|
65
65
|
|
|
66
66
|
|
|
67
|
-
def of_isinstance(spec:
|
|
67
|
+
def of_isinstance(spec: type[T] | tuple, msg: Message = None) -> ta.Callable[[ta.Any], T]:
|
|
68
68
|
def inner(v):
|
|
69
69
|
return isinstance(v, _unpack_isinstance_spec(spec), msg)
|
|
70
70
|
|
|
@@ -155,7 +155,7 @@ def single(obj: ta.Iterable[T], message: Message = None) -> T:
|
|
|
155
155
|
return value
|
|
156
156
|
|
|
157
157
|
|
|
158
|
-
def optional_single(obj: ta.Iterable[T], message: Message = None) ->
|
|
158
|
+
def optional_single(obj: ta.Iterable[T], message: Message = None) -> T | None:
|
|
159
159
|
it = iter(obj)
|
|
160
160
|
try:
|
|
161
161
|
value = next(it)
|
|
@@ -176,7 +176,7 @@ def none(v: ta.Any, msg: Message = None) -> None:
|
|
|
176
176
|
_raise(ValueError, 'Must be None', msg, v)
|
|
177
177
|
|
|
178
178
|
|
|
179
|
-
def not_none(v:
|
|
179
|
+
def not_none(v: T | None, msg: Message = None) -> T:
|
|
180
180
|
if v is None:
|
|
181
181
|
_raise(ValueError, 'Must not be None', msg, v)
|
|
182
182
|
return v
|
|
@@ -206,13 +206,13 @@ def is_not(v: T, *os: ta.Any, msg: Message = None) -> T:
|
|
|
206
206
|
return v
|
|
207
207
|
|
|
208
208
|
|
|
209
|
-
def callable(v: T, msg: Message = None) -> T:
|
|
209
|
+
def callable(v: T, msg: Message = None) -> T: # noqa
|
|
210
210
|
if not _callable(v):
|
|
211
211
|
_raise(TypeError, 'Must be callable', msg, v)
|
|
212
212
|
return v # type: ignore
|
|
213
213
|
|
|
214
214
|
|
|
215
|
-
def non_empty_str(v:
|
|
215
|
+
def non_empty_str(v: str | None, msg: Message = None) -> str:
|
|
216
216
|
if not _isinstance(v, str) or not v:
|
|
217
217
|
_raise(ValueError, 'Must be non-empty str', msg, v)
|
|
218
218
|
return v
|
omlish/collections/__init__.py
CHANGED
|
@@ -1,63 +1,98 @@
|
|
|
1
|
-
from .coerce import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
from .frozen import
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
from .
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
from .
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
from .
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
from .
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
from .
|
|
62
|
-
|
|
63
|
-
|
|
1
|
+
from .coerce import ( # noqa
|
|
2
|
+
abs_set,
|
|
3
|
+
abs_set_of,
|
|
4
|
+
abs_set_of_or_none,
|
|
5
|
+
abs_set_or_none,
|
|
6
|
+
frozenset_,
|
|
7
|
+
frozenset_of,
|
|
8
|
+
frozenset_of_or_none,
|
|
9
|
+
frozenset_or_none,
|
|
10
|
+
map,
|
|
11
|
+
map_of,
|
|
12
|
+
map_of_or_none,
|
|
13
|
+
map_or_none,
|
|
14
|
+
opt_abs_set,
|
|
15
|
+
opt_abs_set_of,
|
|
16
|
+
opt_frozenset,
|
|
17
|
+
opt_frozenset_of,
|
|
18
|
+
opt_map,
|
|
19
|
+
opt_map_of,
|
|
20
|
+
opt_seq,
|
|
21
|
+
opt_seq_of,
|
|
22
|
+
seq,
|
|
23
|
+
seq_of,
|
|
24
|
+
seq_of_or_none,
|
|
25
|
+
seq_or_none,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
from .frozen import ( # noqa
|
|
29
|
+
Frozen,
|
|
30
|
+
FrozenDict,
|
|
31
|
+
FrozenList,
|
|
32
|
+
frozendict,
|
|
33
|
+
frozenlist,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
from .identity import ( # noqa
|
|
37
|
+
IdentityKeyDict,
|
|
38
|
+
IdentitySet,
|
|
39
|
+
IdentityWrapper,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
from .indexed import ( # noqa
|
|
43
|
+
IndexedSeq,
|
|
44
|
+
IndexedSetSeq,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
from .mappings import ( # noqa
|
|
48
|
+
MissingDict,
|
|
49
|
+
TypeMap,
|
|
50
|
+
TypeMultiMap,
|
|
51
|
+
guarded_map_update,
|
|
52
|
+
multikey_dict,
|
|
53
|
+
yield_dict_init,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
from .ordered import ( # noqa
|
|
57
|
+
OrderedFrozenSet,
|
|
58
|
+
OrderedSet,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
from .persistent import ( # noqa
|
|
62
|
+
PersistentMap,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
from .skiplist import ( # noqa
|
|
66
|
+
SkipList,
|
|
67
|
+
SkipListDict,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
from .sorted import ( # noqa
|
|
71
|
+
SortedCollection,
|
|
72
|
+
SortedListDict,
|
|
73
|
+
SortedMapping,
|
|
74
|
+
SortedMutableMapping,
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
from .treapmap import ( # noqa
|
|
78
|
+
new_treap_map,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
from .unmodifiable import ( # noqa
|
|
82
|
+
Unmodifiable,
|
|
83
|
+
UnmodifiableMapping,
|
|
84
|
+
UnmodifiableSequence,
|
|
85
|
+
UnmodifiableSet,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
from .utils import ( # noqa
|
|
89
|
+
all_equal,
|
|
90
|
+
all_not_equal,
|
|
91
|
+
indexes,
|
|
92
|
+
key_cmp,
|
|
93
|
+
mut_toposort,
|
|
94
|
+
partition,
|
|
95
|
+
toposort,
|
|
96
|
+
unique,
|
|
97
|
+
unique_dict,
|
|
98
|
+
)
|
omlish/collections/_abc.py
CHANGED
omlish/collections/_io_abc.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# ruff: noqa: ANN204
|
|
2
|
+
|
|
1
3
|
class IOBase:
|
|
2
4
|
def seek(self, pos, whence=0): ...
|
|
3
5
|
|
|
@@ -16,7 +18,7 @@ class IOBase:
|
|
|
16
18
|
def writable(self): ...
|
|
17
19
|
|
|
18
20
|
@property
|
|
19
|
-
def closed(self): ...
|
|
21
|
+
def closed(self): ... # noqa
|
|
20
22
|
|
|
21
23
|
def __enter__(self): ...
|
|
22
24
|
|
|
@@ -64,7 +66,7 @@ class TextIOBase(IOBase):
|
|
|
64
66
|
|
|
65
67
|
def truncate(self, pos=None): ...
|
|
66
68
|
|
|
67
|
-
def readline(self): ...
|
|
69
|
+
def readline(self, size=-1): ...
|
|
68
70
|
|
|
69
71
|
def detach(self): ...
|
|
70
72
|
|
|
@@ -26,27 +26,27 @@ class _HashedSeq(list):
|
|
|
26
26
|
|
|
27
27
|
def __init__(
|
|
28
28
|
self,
|
|
29
|
-
tup:
|
|
30
|
-
hasher: ta.Callable[[ta.Any], int] = hash
|
|
29
|
+
tup: tuple,
|
|
30
|
+
hasher: ta.Callable[[ta.Any], int] = hash,
|
|
31
31
|
) -> None:
|
|
32
32
|
super().__init__()
|
|
33
33
|
|
|
34
34
|
self[:] = tup
|
|
35
35
|
self.hash_value = hasher(tup)
|
|
36
36
|
|
|
37
|
-
def __hash__(self):
|
|
37
|
+
def __hash__(self) -> int: # type: ignore
|
|
38
38
|
return self.hash_value
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
def _make_key(
|
|
42
|
-
args:
|
|
43
|
-
kwargs:
|
|
42
|
+
args: tuple,
|
|
43
|
+
kwargs: dict[str, ta.Any],
|
|
44
44
|
typed: bool,
|
|
45
45
|
kwd_mark=(object(),),
|
|
46
46
|
fasttypes=frozenset([int, str, frozenset, type(None)]),
|
|
47
|
-
tuple=tuple,
|
|
48
|
-
type=type,
|
|
49
|
-
len=len
|
|
47
|
+
tuple=tuple, # noqa
|
|
48
|
+
type=type, # noqa
|
|
49
|
+
len=len, # noqa
|
|
50
50
|
) -> ta.Any:
|
|
51
51
|
key = args
|
|
52
52
|
if kwargs:
|
|
@@ -81,7 +81,7 @@ class _CacheDescriptor:
|
|
|
81
81
|
fn: ta.Callable,
|
|
82
82
|
scope: Scope,
|
|
83
83
|
typed: bool,
|
|
84
|
-
**kwargs: ta.Any
|
|
84
|
+
**kwargs: ta.Any,
|
|
85
85
|
) -> None:
|
|
86
86
|
super().__init__()
|
|
87
87
|
|
|
@@ -109,7 +109,7 @@ class _CacheDescriptor:
|
|
|
109
109
|
def _build(self, fn: ta.Callable, cache: Cache):
|
|
110
110
|
def miss(key, result):
|
|
111
111
|
if isinstance(result, Ignore):
|
|
112
|
-
return result._value
|
|
112
|
+
return result._value # noqa
|
|
113
113
|
else:
|
|
114
114
|
cache[key] = result
|
|
115
115
|
return result
|
|
@@ -175,9 +175,9 @@ class _CacheDescriptor:
|
|
|
175
175
|
|
|
176
176
|
|
|
177
177
|
def cache(
|
|
178
|
-
scope:
|
|
178
|
+
scope: Scope | str = Scope.INSTANCE,
|
|
179
179
|
typed: bool = False,
|
|
180
|
-
**kwargs
|
|
180
|
+
**kwargs,
|
|
181
181
|
) -> CC:
|
|
182
182
|
if not isinstance(scope, Scope):
|
|
183
183
|
scope = getattr(Scope, scope.upper()) # noqa
|