omlish 0.0.0.dev2__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 +1 -2
- omlish/argparse.py +4 -4
- omlish/asyncs/__init__.py +2 -2
- omlish/asyncs/anyio.py +13 -11
- omlish/asyncs/asyncs.py +1 -3
- omlish/asyncs/futures.py +10 -9
- omlish/c3.py +1 -1
- omlish/check.py +3 -3
- 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 +8 -8
- omlish/collections/cache/impl.py +24 -17
- omlish/collections/cache/types.py +1 -1
- omlish/collections/coerce.py +1 -1
- omlish/collections/frozen.py +6 -6
- omlish/collections/identity.py +3 -4
- omlish/collections/mappings.py +2 -2
- omlish/collections/ordered.py +7 -7
- omlish/collections/skiplist.py +1 -1
- omlish/collections/sorted.py +1 -1
- omlish/collections/treap.py +25 -0
- omlish/collections/treapmap.py +57 -5
- omlish/collections/unmodifiable.py +9 -9
- omlish/collections/utils.py +1 -1
- omlish/configs/flattening.py +7 -6
- omlish/configs/props.py +3 -3
- omlish/dataclasses/__init__.py +1 -1
- omlish/dataclasses/impl/__init__.py +17 -1
- omlish/dataclasses/impl/api.py +10 -11
- omlish/dataclasses/impl/as_.py +4 -4
- omlish/dataclasses/impl/exceptions.py +1 -1
- omlish/dataclasses/impl/fields.py +7 -7
- omlish/dataclasses/impl/frozen.py +2 -2
- omlish/dataclasses/impl/init.py +5 -5
- omlish/dataclasses/impl/internals.py +1 -1
- omlish/dataclasses/impl/metaclass.py +1 -1
- omlish/dataclasses/impl/order.py +1 -1
- omlish/dataclasses/impl/replace.py +1 -1
- omlish/dataclasses/impl/repr.py +4 -4
- omlish/dataclasses/impl/utils.py +6 -6
- omlish/defs.py +13 -17
- omlish/{procfs.py → diag/procfs.py} +22 -24
- omlish/diag/ps.py +47 -0
- omlish/{replserver → diag/replserver}/console.py +18 -20
- omlish/{replserver → diag/replserver}/server.py +8 -8
- omlish/dispatch/dispatch.py +5 -8
- omlish/dispatch/functions.py +1 -1
- omlish/dispatch/methods.py +4 -5
- omlish/docker.py +1 -1
- omlish/dynamic.py +8 -8
- omlish/fnpairs.py +311 -0
- omlish/graphs/trees.py +13 -13
- omlish/inject/__init__.py +7 -7
- omlish/inject/elements.py +1 -1
- omlish/inject/exceptions.py +7 -7
- omlish/inject/impl/elements.py +4 -4
- omlish/inject/impl/injector.py +5 -5
- omlish/inject/impl/inspect.py +2 -2
- omlish/inject/impl/scopes.py +9 -9
- omlish/inject/proxy.py +5 -5
- omlish/iterators.py +19 -24
- omlish/json.py +7 -6
- omlish/lang/__init__.py +9 -4
- omlish/lang/cached.py +2 -5
- omlish/lang/classes/__init__.py +2 -2
- omlish/lang/classes/abstract.py +2 -2
- omlish/lang/classes/restrict.py +14 -14
- omlish/lang/classes/simple.py +1 -1
- omlish/lang/classes/virtual.py +5 -5
- omlish/lang/clsdct.py +1 -1
- omlish/lang/cmp.py +2 -2
- omlish/lang/contextmanagers.py +12 -14
- omlish/lang/descriptors.py +16 -4
- omlish/lang/exceptions.py +1 -1
- omlish/lang/functions.py +58 -22
- omlish/lang/imports.py +22 -27
- omlish/lang/iterables.py +2 -2
- omlish/lang/maybes.py +1 -0
- omlish/lang/objects.py +15 -9
- omlish/lang/resolving.py +1 -1
- omlish/lang/strings.py +1 -1
- omlish/lang/typing.py +3 -3
- omlish/libc.py +9 -5
- 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 +3 -3
- omlish/marshal/exceptions.py +1 -1
- omlish/marshal/global_.py +10 -4
- omlish/marshal/objects.py +1 -2
- omlish/marshal/registries.py +3 -3
- omlish/marshal/utils.py +2 -2
- omlish/marshal/values.py +1 -1
- omlish/math.py +9 -9
- omlish/reflect.py +3 -3
- omlish/stats.py +4 -5
- omlish/term.py +1 -1
- omlish/testing/pydevd.py +26 -6
- omlish/testing/pytest/inject/harness.py +1 -1
- omlish/testing/pytest/plugins/pydevd.py +1 -1
- omlish/testing/pytest/plugins/switches.py +1 -1
- omlish/text/delimit.py +3 -6
- {omlish-0.0.0.dev2.dist-info → omlish-0.0.0.dev3.dist-info}/METADATA +1 -1
- omlish-0.0.0.dev3.dist-info/RECORD +191 -0
- {omlish-0.0.0.dev2.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-0.0.0.dev2.dist-info/RECORD +0 -193
- /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/sql/{_abcs.py → _abc.py} +0 -0
- {omlish-0.0.0.dev2.dist-info → omlish-0.0.0.dev3.dist-info}/LICENSE +0 -0
- {omlish-0.0.0.dev2.dist-info → omlish-0.0.0.dev3.dist-info}/top_level.txt +0 -0
omlish/lang/functions.py
CHANGED
|
@@ -7,14 +7,21 @@ from .descriptors import is_method_descriptor
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
T = ta.TypeVar('T')
|
|
10
|
+
P = ta.ParamSpec('P')
|
|
10
11
|
CallableT = ta.TypeVar('CallableT', bound=ta.Callable)
|
|
11
12
|
|
|
12
13
|
|
|
14
|
+
##
|
|
15
|
+
|
|
16
|
+
|
|
13
17
|
def is_lambda(f: ta.Any) -> bool:
|
|
14
18
|
l = lambda: 0
|
|
15
19
|
return isinstance(f, type(l)) and f.__name__ == l.__name__
|
|
16
20
|
|
|
17
21
|
|
|
22
|
+
##
|
|
23
|
+
|
|
24
|
+
|
|
18
25
|
def maybe_call(obj: ta.Any, att: str, *args, default: ta.Any = None, **kwargs) -> ta.Any:
|
|
19
26
|
try:
|
|
20
27
|
fn = getattr(obj, att)
|
|
@@ -24,6 +31,16 @@ def maybe_call(obj: ta.Any, att: str, *args, default: ta.Any = None, **kwargs) -
|
|
|
24
31
|
return fn(*args, **kwargs)
|
|
25
32
|
|
|
26
33
|
|
|
34
|
+
def recurse(fn: ta.Callable[..., T], *args, **kwargs) -> T:
|
|
35
|
+
def rec(*args, **kwargs) -> T:
|
|
36
|
+
return fn(rec, *args, **kwargs)
|
|
37
|
+
|
|
38
|
+
return rec(*args, **kwargs)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
##
|
|
42
|
+
|
|
43
|
+
|
|
27
44
|
def unwrap_func(fn: ta.Callable) -> ta.Callable:
|
|
28
45
|
fn, _ = unwrap_func_with_partials(fn)
|
|
29
46
|
return fn
|
|
@@ -41,38 +58,51 @@ def unwrap_func_with_partials(fn: ta.Callable) -> tuple[ta.Callable, list[functo
|
|
|
41
58
|
nxt = getattr(fn, '__wrapped__', None)
|
|
42
59
|
if not callable(nxt):
|
|
43
60
|
break
|
|
44
|
-
|
|
61
|
+
if nxt is fn:
|
|
45
62
|
raise TypeError(fn)
|
|
46
63
|
fn = nxt
|
|
47
64
|
return fn, ps
|
|
48
65
|
|
|
49
66
|
|
|
67
|
+
##
|
|
68
|
+
|
|
69
|
+
|
|
50
70
|
def raise_(o: BaseException) -> ta.NoReturn:
|
|
51
71
|
raise o
|
|
52
72
|
|
|
53
73
|
|
|
74
|
+
def raising(o: BaseException) -> ta.Callable[..., ta.NoReturn]:
|
|
75
|
+
def inner(*args, **kwargs):
|
|
76
|
+
raise o
|
|
77
|
+
return inner
|
|
78
|
+
|
|
79
|
+
|
|
54
80
|
def try_(
|
|
81
|
+
fn: ta.Callable[P, T],
|
|
55
82
|
exc: type[Exception] | ta.Iterable[type[Exception]] = Exception,
|
|
56
83
|
default: T | None = None,
|
|
57
|
-
) -> ta.Callable[
|
|
58
|
-
def
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return default
|
|
64
|
-
|
|
65
|
-
return inner
|
|
84
|
+
) -> ta.Callable[P, T]:
|
|
85
|
+
def inner(*args, **kwargs):
|
|
86
|
+
try:
|
|
87
|
+
return fn(*args, **kwargs)
|
|
88
|
+
except exct:
|
|
89
|
+
return default
|
|
66
90
|
|
|
67
91
|
exct = (exc,) if isinstance(exc, type) else tuple(exc)
|
|
68
|
-
return
|
|
92
|
+
return inner
|
|
69
93
|
|
|
70
94
|
|
|
71
|
-
def
|
|
72
|
-
def
|
|
73
|
-
|
|
95
|
+
def finally_(fn: ta.Callable[P, T], fin: ta.Callable) -> ta.Callable[P, T]:
|
|
96
|
+
def inner(*args, **kwargs):
|
|
97
|
+
try:
|
|
98
|
+
return fn(*args, **kwargs)
|
|
99
|
+
finally:
|
|
100
|
+
fin()
|
|
101
|
+
|
|
102
|
+
return inner
|
|
74
103
|
|
|
75
|
-
|
|
104
|
+
|
|
105
|
+
##
|
|
76
106
|
|
|
77
107
|
|
|
78
108
|
def identity(obj: T) -> T:
|
|
@@ -98,21 +128,24 @@ def is_not_none(o: ta.Any) -> bool:
|
|
|
98
128
|
return o is not None
|
|
99
129
|
|
|
100
130
|
|
|
101
|
-
class
|
|
131
|
+
class VoidError(Exception):
|
|
102
132
|
pass
|
|
103
133
|
|
|
104
134
|
|
|
105
135
|
class Void:
|
|
106
136
|
|
|
107
|
-
def __new__(cls, *args, **kwargs):
|
|
108
|
-
raise
|
|
137
|
+
def __new__(cls, *args: ta.Any, **kwargs: ta.Any) -> None: # type: ignore # noqa
|
|
138
|
+
raise VoidError
|
|
139
|
+
|
|
140
|
+
def __init_subclass__(cls, **kwargs: ta.Any) -> None:
|
|
141
|
+
raise VoidError
|
|
109
142
|
|
|
110
|
-
def __init_subclass__(cls, **kwargs):
|
|
111
|
-
raise VoidException
|
|
112
143
|
|
|
144
|
+
def void(*args: ta.Any, **kwargs: ta.Any) -> ta.NoReturn:
|
|
145
|
+
raise VoidError
|
|
113
146
|
|
|
114
|
-
|
|
115
|
-
|
|
147
|
+
|
|
148
|
+
##
|
|
116
149
|
|
|
117
150
|
|
|
118
151
|
_MISSING = object()
|
|
@@ -142,6 +175,9 @@ def periodically(
|
|
|
142
175
|
return inner # type: ignore
|
|
143
176
|
|
|
144
177
|
|
|
178
|
+
##
|
|
179
|
+
|
|
180
|
+
|
|
145
181
|
@dc.dataclass(init=False)
|
|
146
182
|
class Args:
|
|
147
183
|
args: ta.Sequence[ta.Any]
|
omlish/lang/imports.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import contextlib
|
|
1
2
|
import functools
|
|
2
|
-
import importlib
|
|
3
|
+
import importlib.resources
|
|
3
4
|
import sys
|
|
4
5
|
import types
|
|
5
6
|
import typing as ta
|
|
@@ -17,7 +18,7 @@ def lazy_import(name: str, package: str | None = None) -> ta.Callable[[], ta.Any
|
|
|
17
18
|
def proxy_import(name: str, package: str | None = None) -> types.ModuleType:
|
|
18
19
|
omod = None
|
|
19
20
|
|
|
20
|
-
def __getattr__(att):
|
|
21
|
+
def __getattr__(att): # noqa
|
|
21
22
|
nonlocal omod
|
|
22
23
|
if omod is None:
|
|
23
24
|
omod = importlib.import_module(name, package=package)
|
|
@@ -31,9 +32,6 @@ def proxy_import(name: str, package: str | None = None) -> types.ModuleType:
|
|
|
31
32
|
##
|
|
32
33
|
|
|
33
34
|
|
|
34
|
-
_pkg_resources = lazy_import('pkg_resources')
|
|
35
|
-
|
|
36
|
-
|
|
37
35
|
def import_module(dotted_path: str) -> types.ModuleType:
|
|
38
36
|
if not dotted_path:
|
|
39
37
|
raise ImportError(dotted_path)
|
|
@@ -42,7 +40,7 @@ def import_module(dotted_path: str) -> types.ModuleType:
|
|
|
42
40
|
try:
|
|
43
41
|
mod = getattr(mod, name)
|
|
44
42
|
except AttributeError:
|
|
45
|
-
raise AttributeError('Module
|
|
43
|
+
raise AttributeError(f'Module {mod!r} has no attribute {name!r}') from None
|
|
46
44
|
return mod
|
|
47
45
|
|
|
48
46
|
|
|
@@ -52,7 +50,7 @@ def import_module_attr(dotted_path: str) -> ta.Any:
|
|
|
52
50
|
try:
|
|
53
51
|
return getattr(mod, class_name)
|
|
54
52
|
except AttributeError:
|
|
55
|
-
raise AttributeError('Module
|
|
53
|
+
raise AttributeError(f'Module {module_name!r} has no attr {class_name!r}') from None
|
|
56
54
|
|
|
57
55
|
|
|
58
56
|
SPECIAL_IMPORTABLE: ta.AbstractSet[str] = frozenset([
|
|
@@ -65,46 +63,43 @@ def yield_importable(
|
|
|
65
63
|
package_root: str,
|
|
66
64
|
*,
|
|
67
65
|
recursive: bool = False,
|
|
68
|
-
filter: ta.Callable[[str], bool] | None = None,
|
|
66
|
+
filter: ta.Callable[[str], bool] | None = None, # noqa
|
|
69
67
|
include_special: bool = False,
|
|
70
68
|
) -> ta.Iterator[str]:
|
|
71
|
-
def rec(
|
|
72
|
-
if
|
|
69
|
+
def rec(cur):
|
|
70
|
+
if cur.split('.')[-1] == '__pycache__':
|
|
73
71
|
return
|
|
74
72
|
|
|
75
73
|
try:
|
|
76
|
-
module = sys.modules[
|
|
74
|
+
module = sys.modules[cur]
|
|
77
75
|
except KeyError:
|
|
78
76
|
try:
|
|
79
|
-
__import__(
|
|
77
|
+
__import__(cur)
|
|
80
78
|
except ImportError:
|
|
81
79
|
return
|
|
82
|
-
module = sys.modules[
|
|
80
|
+
module = sys.modules[cur]
|
|
83
81
|
|
|
84
82
|
# FIXME: pyox
|
|
85
83
|
if getattr(module, '__file__', None) is None:
|
|
86
84
|
return
|
|
87
85
|
|
|
88
|
-
for file in
|
|
89
|
-
if file.endswith('.py'):
|
|
90
|
-
if not (include_special or file not in SPECIAL_IMPORTABLE):
|
|
86
|
+
for file in importlib.resources.files(cur).iterdir():
|
|
87
|
+
if file.is_file() and file.name.endswith('.py'):
|
|
88
|
+
if not (include_special or file.name not in SPECIAL_IMPORTABLE):
|
|
91
89
|
continue
|
|
92
90
|
|
|
93
|
-
name =
|
|
91
|
+
name = cur + '.' + file.name[:-3]
|
|
94
92
|
if filter is not None and not filter(name):
|
|
95
93
|
continue
|
|
96
94
|
|
|
97
95
|
yield name
|
|
98
96
|
|
|
99
|
-
elif recursive and
|
|
100
|
-
name =
|
|
97
|
+
elif recursive and file.is_dir():
|
|
98
|
+
name = cur + '.' + file.name
|
|
101
99
|
if filter is not None and not filter(name):
|
|
102
100
|
continue
|
|
103
|
-
|
|
104
|
-
try:
|
|
101
|
+
with contextlib.suppress(ImportError, NotImplementedError):
|
|
105
102
|
yield from rec(name)
|
|
106
|
-
except (ImportError, NotImplementedError):
|
|
107
|
-
pass
|
|
108
103
|
|
|
109
104
|
yield from rec(package_root)
|
|
110
105
|
|
|
@@ -112,10 +107,10 @@ def yield_importable(
|
|
|
112
107
|
def yield_import_all(
|
|
113
108
|
package_root: str,
|
|
114
109
|
*,
|
|
115
|
-
globals: dict[str, ta.Any] | None = None,
|
|
116
|
-
locals: dict[str, ta.Any] | None = None,
|
|
110
|
+
globals: dict[str, ta.Any] | None = None, # noqa
|
|
111
|
+
locals: dict[str, ta.Any] | None = None, # noqa
|
|
117
112
|
recursive: bool = False,
|
|
118
|
-
filter: ta.Callable[[str], bool] | None = None,
|
|
113
|
+
filter: ta.Callable[[str], bool] | None = None, # noqa
|
|
119
114
|
include_special: bool = False,
|
|
120
115
|
) -> ta.Iterator[str]:
|
|
121
116
|
for import_path in yield_importable(
|
|
@@ -132,7 +127,7 @@ def import_all(
|
|
|
132
127
|
package_root: str,
|
|
133
128
|
*,
|
|
134
129
|
recursive: bool = False,
|
|
135
|
-
filter: ta.Callable[[str], bool] | None = None,
|
|
130
|
+
filter: ta.Callable[[str], bool] | None = None, # noqa
|
|
136
131
|
include_special: bool = False,
|
|
137
132
|
) -> None:
|
|
138
133
|
for _ in yield_import_all(
|
omlish/lang/iterables.py
CHANGED
|
@@ -28,13 +28,13 @@ def exhaust(it: ta.Iterable[ta.Any]) -> None:
|
|
|
28
28
|
pass
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
def peek(vs: ta.Iterable[T]) ->
|
|
31
|
+
def peek(vs: ta.Iterable[T]) -> tuple[T, ta.Iterator[T]]:
|
|
32
32
|
it = iter(vs)
|
|
33
33
|
v = next(it)
|
|
34
34
|
return v, itertools.chain(iter((v,)), it)
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
Rangeable: ta.TypeAlias = int |
|
|
37
|
+
Rangeable: ta.TypeAlias = int | tuple[int] | tuple[int, int] | ta.Iterable[int]
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
def asrange(i: Rangeable) -> ta.Iterable[int]:
|
omlish/lang/maybes.py
CHANGED
omlish/lang/objects.py
CHANGED
|
@@ -9,18 +9,22 @@ T = ta.TypeVar('T')
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
def attr_repr(obj: ta.Any, *attrs: str) -> str:
|
|
12
|
-
return '
|
|
13
|
-
type(obj).__name__,
|
|
14
|
-
', '.join('%s=%r' % (attr, getattr(obj, attr)) for attr in attrs))
|
|
12
|
+
return f'{type(obj).__name__}({", ".join(f"{attr}={getattr(obj, attr)!r}" for attr in attrs)})'
|
|
15
13
|
|
|
16
14
|
|
|
17
15
|
def arg_repr(*args, **kwargs) -> str:
|
|
18
16
|
return ', '.join(*(
|
|
19
17
|
list(map(repr, args)) +
|
|
20
|
-
[f'{k}={
|
|
18
|
+
[f'{k}={v!r}' for k, v in kwargs.items()]
|
|
21
19
|
))
|
|
22
20
|
|
|
23
21
|
|
|
22
|
+
def opt_repr(obj: ta.Any) -> str | None:
|
|
23
|
+
if obj is None:
|
|
24
|
+
return None
|
|
25
|
+
return repr(obj)
|
|
26
|
+
|
|
27
|
+
|
|
24
28
|
##
|
|
25
29
|
|
|
26
30
|
|
|
@@ -29,7 +33,7 @@ def new_type(
|
|
|
29
33
|
bases: ta.Sequence[ta.Any],
|
|
30
34
|
namespace: ta.Mapping[str, ta.Any],
|
|
31
35
|
**kwargs,
|
|
32
|
-
) ->
|
|
36
|
+
) -> type:
|
|
33
37
|
return types.new_class(
|
|
34
38
|
name,
|
|
35
39
|
tuple(bases),
|
|
@@ -40,12 +44,12 @@ def new_type(
|
|
|
40
44
|
|
|
41
45
|
def super_meta(
|
|
42
46
|
super_meta: ta.Any,
|
|
43
|
-
meta:
|
|
47
|
+
meta: type,
|
|
44
48
|
name: str,
|
|
45
49
|
bases: ta.Sequence[ta.Any],
|
|
46
50
|
namespace: ta.MutableMapping[str, ta.Any],
|
|
47
51
|
**kwargs,
|
|
48
|
-
) ->
|
|
52
|
+
) -> type:
|
|
49
53
|
"""Per types.new_class"""
|
|
50
54
|
resolved_bases = types.resolve_bases(bases)
|
|
51
55
|
if resolved_bases is not bases:
|
|
@@ -75,19 +79,21 @@ class SimpleProxy(ta.Generic[T]):
|
|
|
75
79
|
if instance is None:
|
|
76
80
|
return self
|
|
77
81
|
setattr(object.__getattribute__(instance, '__wrapped__'), self._attr, value)
|
|
82
|
+
return None
|
|
78
83
|
|
|
79
84
|
def __delete__(self, instance):
|
|
80
85
|
if instance is None:
|
|
81
86
|
return self
|
|
82
87
|
delattr(object.__getattribute__(instance, '__wrapped__'), self._attr)
|
|
88
|
+
return None
|
|
83
89
|
|
|
84
|
-
__wrapped_attrs__: ta.Iterable[str] =
|
|
90
|
+
__wrapped_attrs__: ta.ClassVar[ta.Iterable[str]] = ()
|
|
85
91
|
|
|
86
92
|
def __init__(self, wrapped: T) -> None:
|
|
87
93
|
super().__init__()
|
|
88
94
|
object.__setattr__(self, '__wrapped__', wrapped)
|
|
89
95
|
|
|
90
|
-
def __init_subclass__(cls, **kwargs):
|
|
96
|
+
def __init_subclass__(cls, **kwargs: ta.Any) -> None:
|
|
91
97
|
super().__init_subclass__(**kwargs)
|
|
92
98
|
|
|
93
99
|
for attr in cls.__wrapped_attrs__:
|
omlish/lang/resolving.py
CHANGED
omlish/lang/strings.py
CHANGED
|
@@ -22,7 +22,7 @@ def camel_case(name: str) -> str:
|
|
|
22
22
|
|
|
23
23
|
def snake_case(name: str) -> str:
|
|
24
24
|
uppers: list[int | None] = [i for i, c in enumerate(name) if c.isupper()]
|
|
25
|
-
return '_'.join([name[l:r].lower() for l, r in zip([None
|
|
25
|
+
return '_'.join([name[l:r].lower() for l, r in zip([None, *uppers], [*uppers, None])]).strip('_')
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
def is_dunder(name: str) -> bool:
|
omlish/lang/typing.py
CHANGED
|
@@ -37,13 +37,13 @@ def _update_wrapper_no_anns(wrapper, wrapped):
|
|
|
37
37
|
return wrapper
|
|
38
38
|
|
|
39
39
|
|
|
40
|
-
def typed_lambda(ret=_MISSING, **kw):
|
|
40
|
+
def typed_lambda(ret=_MISSING, **kw): # noqa
|
|
41
41
|
def inner(fn):
|
|
42
42
|
ns = {}
|
|
43
43
|
ns['__fn'] = fn
|
|
44
44
|
proto = ['def __lam(']
|
|
45
45
|
call = ['return __fn(']
|
|
46
|
-
pkw =
|
|
46
|
+
pkw = dict(kw)
|
|
47
47
|
for i, (n, t) in enumerate(pkw.items()):
|
|
48
48
|
if i:
|
|
49
49
|
call.append(', ')
|
|
@@ -69,7 +69,7 @@ def typed_lambda(ret=_MISSING, **kw):
|
|
|
69
69
|
return inner
|
|
70
70
|
|
|
71
71
|
|
|
72
|
-
def typed_partial(obj, **kw):
|
|
72
|
+
def typed_partial(obj, **kw): # noqa
|
|
73
73
|
for k in kw:
|
|
74
74
|
if k.startswith('__'):
|
|
75
75
|
raise NameError(k)
|
omlish/libc.py
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# ruff: noqa: ANN201
|
|
2
|
+
# ruff: noqa: N801
|
|
3
|
+
# ruff: noqa: N802
|
|
4
|
+
|
|
1
5
|
import ctypes as ct
|
|
2
6
|
import errno
|
|
3
7
|
import platform
|
|
@@ -37,14 +41,14 @@ def lasterr() -> tuple[int, str]:
|
|
|
37
41
|
|
|
38
42
|
|
|
39
43
|
# int raise(int sig);
|
|
40
|
-
libc._raise = libc['raise'] # type: ignore
|
|
41
|
-
libc._raise.restype = ct.c_int
|
|
42
|
-
libc._raise.argtypes = [ct.c_int]
|
|
43
|
-
_raise = libc._raise
|
|
44
|
+
libc._raise = libc['raise'] # type: ignore # noqa
|
|
45
|
+
libc._raise.restype = ct.c_int # noqa
|
|
46
|
+
libc._raise.argtypes = [ct.c_int] # noqa
|
|
47
|
+
_raise = libc._raise # noqa
|
|
44
48
|
|
|
45
49
|
|
|
46
50
|
def sigtrap() -> None:
|
|
47
|
-
libc._raise(signal.SIGTRAP)
|
|
51
|
+
libc._raise(signal.SIGTRAP) # noqa
|
|
48
52
|
|
|
49
53
|
|
|
50
54
|
##
|
omlish/logs/_abc.py
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# ruff: noqa: A002
|
|
2
|
+
# ruff: noqa: N802
|
|
3
|
+
# ruff: noqa: N815
|
|
4
|
+
|
|
1
5
|
import types
|
|
2
6
|
import typing as ta
|
|
3
7
|
|
|
@@ -181,7 +185,7 @@ class Logger(Filterer, ta.Protocol):
|
|
|
181
185
|
|
|
182
186
|
def log(self, level: Level, msg: str, *args: ta.Any, **kwargs: ta.Any) -> None: ...
|
|
183
187
|
|
|
184
|
-
def findCaller(self, stack_info: bool = False, stacklevel: int = 1) -> Caller: ...
|
|
188
|
+
def findCaller(self, stack_info: bool = False, stacklevel: int = 1) -> Caller: ...
|
|
185
189
|
|
|
186
190
|
def makeRecord(
|
|
187
191
|
self,
|
omlish/logs/filters.py
CHANGED
omlish/logs/formatters.py
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
# ruff: noqa: ANN201
|
|
2
|
+
# ruff: noqa: N802
|
|
3
|
+
|
|
1
4
|
import datetime
|
|
2
5
|
import logging
|
|
6
|
+
import typing as ta
|
|
3
7
|
|
|
4
8
|
from .. import json
|
|
5
9
|
from .. import term
|
|
@@ -20,7 +24,7 @@ class StandardLogFormatter(logging.Formatter):
|
|
|
20
24
|
|
|
21
25
|
class ColorLogFormatter(StandardLogFormatter):
|
|
22
26
|
|
|
23
|
-
LEVEL_COLORS = {
|
|
27
|
+
LEVEL_COLORS: ta.Mapping[int, term.SGRs.FG] = {
|
|
24
28
|
logging.WARNING: term.SGRs.FG.BRIGHT_YELLOW,
|
|
25
29
|
logging.ERROR: term.SGRs.FG.BRIGHT_RED,
|
|
26
30
|
logging.CRITICAL: term.SGRs.FG.BRIGHT_RED,
|
|
@@ -39,7 +43,7 @@ class ColorLogFormatter(StandardLogFormatter):
|
|
|
39
43
|
|
|
40
44
|
class JsonLogFormatter(logging.Formatter):
|
|
41
45
|
|
|
42
|
-
KEYS = {
|
|
46
|
+
KEYS: ta.Mapping[str, bool] = {
|
|
43
47
|
'name': False,
|
|
44
48
|
'msg': False,
|
|
45
49
|
'args': False,
|
omlish/logs/utils.py
CHANGED
omlish/marshal/base.py
CHANGED
|
@@ -81,7 +81,7 @@ from .. import check
|
|
|
81
81
|
from .. import collections as col
|
|
82
82
|
from .. import lang
|
|
83
83
|
from .. import reflect as rfl
|
|
84
|
-
from .exceptions import
|
|
84
|
+
from .exceptions import UnhandledTypeError
|
|
85
85
|
from .factories import Factory
|
|
86
86
|
from .factories import RecursiveTypeFactory
|
|
87
87
|
from .registries import Registry
|
|
@@ -152,7 +152,7 @@ class MarshalContext(BaseContext, lang.Final):
|
|
|
152
152
|
rty = rfl.type_(o)
|
|
153
153
|
if (m := check.not_none(self.factory)(self, rty)) is not None: # noqa
|
|
154
154
|
return m
|
|
155
|
-
raise
|
|
155
|
+
raise UnhandledTypeError(rty)
|
|
156
156
|
|
|
157
157
|
|
|
158
158
|
@dc.dataclass(frozen=True)
|
|
@@ -163,7 +163,7 @@ class UnmarshalContext(BaseContext, lang.Final):
|
|
|
163
163
|
rty = rfl.type_(o)
|
|
164
164
|
if (m := check.not_none(self.factory)(self, rty)) is not None: # noqa
|
|
165
165
|
return m
|
|
166
|
-
raise
|
|
166
|
+
raise UnhandledTypeError(rty)
|
|
167
167
|
|
|
168
168
|
|
|
169
169
|
##
|
omlish/marshal/exceptions.py
CHANGED
omlish/marshal/global_.py
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import typing as ta
|
|
2
|
+
|
|
3
3
|
from .base import MarshalContext
|
|
4
4
|
from .base import UnmarshalContext
|
|
5
|
+
from .registries import Registry
|
|
6
|
+
from .standard import new_standard_marshaler_factory
|
|
5
7
|
from .standard import new_standard_unmarshaler_factory
|
|
8
|
+
from .values import Value
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
T = ta.TypeVar('T')
|
|
6
12
|
|
|
7
13
|
|
|
8
14
|
##
|
|
@@ -17,7 +23,7 @@ GLOBAL_REGISTRY = Registry()
|
|
|
17
23
|
GLOBAL_MARSHALER_FACTORY = new_standard_marshaler_factory()
|
|
18
24
|
|
|
19
25
|
|
|
20
|
-
def marshal(obj, ty=None, **kwargs):
|
|
26
|
+
def marshal(obj: ta.Any, ty: type | None = None, **kwargs: ta.Any) -> Value:
|
|
21
27
|
mc = MarshalContext(GLOBAL_REGISTRY, factory=GLOBAL_MARSHALER_FACTORY, **kwargs)
|
|
22
28
|
return mc.make(ty if ty is not None else type(obj)).marshal(mc, obj)
|
|
23
29
|
|
|
@@ -28,6 +34,6 @@ def marshal(obj, ty=None, **kwargs):
|
|
|
28
34
|
GLOBAL_UNMARSHALER_FACTORY = new_standard_unmarshaler_factory()
|
|
29
35
|
|
|
30
36
|
|
|
31
|
-
def unmarshal(v, ty, **kwargs):
|
|
37
|
+
def unmarshal(v: Value, ty: type[T], **kwargs: ta.Any) -> T:
|
|
32
38
|
uc = UnmarshalContext(GLOBAL_REGISTRY, factory=GLOBAL_UNMARSHALER_FACTORY, **kwargs)
|
|
33
39
|
return uc.make(ty).unmarshal(uc, v)
|
omlish/marshal/objects.py
CHANGED
|
@@ -98,8 +98,7 @@ class ObjectUnmarshaler(Unmarshaler):
|
|
|
98
98
|
if ukf is not None:
|
|
99
99
|
ukf[ks] = mv # FIXME: unmarshal?
|
|
100
100
|
continue
|
|
101
|
-
|
|
102
|
-
raise
|
|
101
|
+
raise
|
|
103
102
|
if fi.name in kw:
|
|
104
103
|
raise KeyError(f'Duplicate keys for field {fi.name!r}: {ks!r}')
|
|
105
104
|
kw[fi.name] = u.unmarshal(ctx, mv)
|
omlish/marshal/registries.py
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import abc
|
|
2
1
|
import dataclasses as dc
|
|
3
2
|
import threading
|
|
4
3
|
import typing as ta
|
|
5
4
|
|
|
6
5
|
from .. import check
|
|
6
|
+
from .. import lang
|
|
7
7
|
from .. import reflect as rfl
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
class RegistryItem(
|
|
10
|
+
class RegistryItem(lang.Abstract):
|
|
11
11
|
pass
|
|
12
12
|
|
|
13
13
|
|
|
@@ -31,7 +31,7 @@ class Registry:
|
|
|
31
31
|
super().__init__()
|
|
32
32
|
self._mtx = threading.Lock()
|
|
33
33
|
self._dct: dict[rfl.Type, _TypeRegistry] = {}
|
|
34
|
-
self._ps: ta.Sequence[
|
|
34
|
+
self._ps: ta.Sequence[Registry] = []
|
|
35
35
|
|
|
36
36
|
def register(self, rty: rfl.Type, *items: RegistryItem) -> 'Registry':
|
|
37
37
|
check.isinstance(rty, rfl.TYPES)
|
omlish/marshal/utils.py
CHANGED