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/lang/__init__.py
CHANGED
|
@@ -1,112 +1,172 @@
|
|
|
1
|
-
from .cached import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
from .classes import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
from .
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
from .
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
from .contextmanagers import
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
from .
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
from .
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
from .
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
from .
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
from .
|
|
111
|
-
|
|
112
|
-
|
|
1
|
+
from .cached import ( # noqa
|
|
2
|
+
cached_function,
|
|
3
|
+
cached_property,
|
|
4
|
+
)
|
|
5
|
+
|
|
6
|
+
from .classes import ( # noqa
|
|
7
|
+
Abstract,
|
|
8
|
+
Callable,
|
|
9
|
+
Descriptor,
|
|
10
|
+
Final,
|
|
11
|
+
FinalError,
|
|
12
|
+
LazySingleton,
|
|
13
|
+
Marker,
|
|
14
|
+
Namespace,
|
|
15
|
+
NoBool,
|
|
16
|
+
NotInstantiable,
|
|
17
|
+
NotPicklable,
|
|
18
|
+
PackageSealed,
|
|
19
|
+
Picklable,
|
|
20
|
+
Sealed,
|
|
21
|
+
SealedError,
|
|
22
|
+
SimpleMetaDict,
|
|
23
|
+
Singleton,
|
|
24
|
+
Virtual,
|
|
25
|
+
is_abstract,
|
|
26
|
+
is_abstract_class,
|
|
27
|
+
is_abstract_method,
|
|
28
|
+
make_abstract,
|
|
29
|
+
no_bool,
|
|
30
|
+
virtual_check,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
from .clsdct import ( # noqa
|
|
34
|
+
ClassDctFn,
|
|
35
|
+
cls_dct_fn,
|
|
36
|
+
get_caller_cls_dct,
|
|
37
|
+
is_possibly_cls_dct,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
from .cmp import ( # noqa
|
|
41
|
+
Infinity,
|
|
42
|
+
InfinityType,
|
|
43
|
+
NegativeInfinity,
|
|
44
|
+
NegativeInfinityType,
|
|
45
|
+
cmp,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
from .contextmanagers import ( # noqa
|
|
49
|
+
ContextManaged,
|
|
50
|
+
ContextWrapped,
|
|
51
|
+
DefaultLockable,
|
|
52
|
+
ExitStacked,
|
|
53
|
+
Lockable,
|
|
54
|
+
NOP_CONTEXT_MANAGED,
|
|
55
|
+
NOP_CONTEXT_MANAGER,
|
|
56
|
+
NopContextManaged,
|
|
57
|
+
NopContextManager,
|
|
58
|
+
a_defer,
|
|
59
|
+
attr_setting,
|
|
60
|
+
breakpoint_on_exception,
|
|
61
|
+
context_var_setting,
|
|
62
|
+
context_wrapped,
|
|
63
|
+
default_lock,
|
|
64
|
+
defer,
|
|
65
|
+
disposing,
|
|
66
|
+
maybe_managing,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
from .datetimes import ( # noqa
|
|
70
|
+
months_ago,
|
|
71
|
+
parse_date,
|
|
72
|
+
parse_timedelta,
|
|
73
|
+
to_seconds,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
from .descriptors import ( # noqa
|
|
77
|
+
AccessForbiddenError,
|
|
78
|
+
access_forbidden,
|
|
79
|
+
attr_property,
|
|
80
|
+
classonly,
|
|
81
|
+
is_method_descriptor,
|
|
82
|
+
item_property,
|
|
83
|
+
unwrap_method_descriptors,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
from .exceptions import ( # noqa
|
|
87
|
+
Unreachable,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
from .functions import ( # noqa
|
|
91
|
+
Args,
|
|
92
|
+
VoidError,
|
|
93
|
+
constant,
|
|
94
|
+
finally_,
|
|
95
|
+
identity,
|
|
96
|
+
is_lambda,
|
|
97
|
+
is_none,
|
|
98
|
+
is_not_none,
|
|
99
|
+
maybe_call,
|
|
100
|
+
periodically,
|
|
101
|
+
raise_,
|
|
102
|
+
raising,
|
|
103
|
+
recurse,
|
|
104
|
+
try_,
|
|
105
|
+
unwrap_func,
|
|
106
|
+
unwrap_func_with_partials,
|
|
107
|
+
void,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
from .imports import ( # noqa
|
|
111
|
+
import_all,
|
|
112
|
+
import_module,
|
|
113
|
+
import_module_attr,
|
|
114
|
+
lazy_import,
|
|
115
|
+
proxy_import,
|
|
116
|
+
try_import,
|
|
117
|
+
yield_import_all,
|
|
118
|
+
yield_importable,
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
from .iterables import ( # noqa
|
|
122
|
+
BUILTIN_SCALAR_ITERABLE_TYPES,
|
|
123
|
+
asrange,
|
|
124
|
+
exhaust,
|
|
125
|
+
ilen,
|
|
126
|
+
peek,
|
|
127
|
+
prodrange,
|
|
128
|
+
take,
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
from .maybes import ( # noqa
|
|
132
|
+
Maybe,
|
|
133
|
+
empty,
|
|
134
|
+
just,
|
|
135
|
+
maybe,
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
from .objects import ( # noqa
|
|
139
|
+
SimpleProxy,
|
|
140
|
+
arg_repr,
|
|
141
|
+
attr_repr,
|
|
142
|
+
new_type,
|
|
143
|
+
opt_repr,
|
|
144
|
+
super_meta,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
from .strings import ( # noqa
|
|
148
|
+
camel_case,
|
|
149
|
+
indent_lines,
|
|
150
|
+
is_dunder,
|
|
151
|
+
is_ident,
|
|
152
|
+
is_ident_cont,
|
|
153
|
+
is_ident_start,
|
|
154
|
+
is_sunder,
|
|
155
|
+
prefix_lines,
|
|
156
|
+
snake_case,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
from .timeouts import ( # noqa
|
|
160
|
+
DeadlineTimeout,
|
|
161
|
+
InfiniteTimeout,
|
|
162
|
+
Timeout,
|
|
163
|
+
TimeoutLike,
|
|
164
|
+
timeout,
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
from .typing import ( # noqa
|
|
168
|
+
BytesLike,
|
|
169
|
+
protocol_check,
|
|
170
|
+
typed_lambda,
|
|
171
|
+
typed_partial,
|
|
172
|
+
)
|
omlish/lang/cached.py
CHANGED
|
@@ -105,11 +105,11 @@ class _CachedFunction(ta.Generic[T]):
|
|
|
105
105
|
opts: Opts = Opts(),
|
|
106
106
|
keyer: ta.Callable[..., tuple] | None = None,
|
|
107
107
|
values: ta.MutableMapping | None = None,
|
|
108
|
-
value_fn: ta.
|
|
108
|
+
value_fn: ta.Callable[P, T] | None = None,
|
|
109
109
|
) -> None:
|
|
110
110
|
super().__init__()
|
|
111
111
|
|
|
112
|
-
self._fn = fn
|
|
112
|
+
self._fn = (fn,)
|
|
113
113
|
self._opts = opts
|
|
114
114
|
self._keyer = keyer if keyer is not None else _make_cache_keyer(fn, simple=opts.simple_key)
|
|
115
115
|
|
|
@@ -118,6 +118,14 @@ class _CachedFunction(ta.Generic[T]):
|
|
|
118
118
|
self._value_fn = value_fn if value_fn is not None else fn
|
|
119
119
|
functools.update_wrapper(self, fn)
|
|
120
120
|
|
|
121
|
+
@property
|
|
122
|
+
def _fn(self):
|
|
123
|
+
return self.__fn
|
|
124
|
+
|
|
125
|
+
@_fn.setter
|
|
126
|
+
def _fn(self, x):
|
|
127
|
+
self.__fn = x
|
|
128
|
+
|
|
121
129
|
def reset(self) -> None:
|
|
122
130
|
self._values = {}
|
|
123
131
|
|
|
@@ -157,8 +165,8 @@ class _CachedFunctionDescriptor(_CachedFunction[T]):
|
|
|
157
165
|
*,
|
|
158
166
|
instance: ta.Any = None,
|
|
159
167
|
owner: ta.Any = None,
|
|
160
|
-
name:
|
|
161
|
-
**kwargs
|
|
168
|
+
name: str | None = None,
|
|
169
|
+
**kwargs,
|
|
162
170
|
) -> None:
|
|
163
171
|
super().__init__(fn, **kwargs)
|
|
164
172
|
|
|
@@ -173,7 +181,7 @@ class _CachedFunctionDescriptor(_CachedFunction[T]):
|
|
|
173
181
|
if owner is self._owner and (instance is self._instance or scope is classmethod):
|
|
174
182
|
return self
|
|
175
183
|
|
|
176
|
-
fn = self._fn
|
|
184
|
+
fn, = self._fn
|
|
177
185
|
name = self._name
|
|
178
186
|
bound_fn = fn.__get__(instance, owner)
|
|
179
187
|
if self._bound_keyer is None:
|
|
@@ -199,7 +207,7 @@ class _CachedFunctionDescriptor(_CachedFunction[T]):
|
|
|
199
207
|
return bound
|
|
200
208
|
|
|
201
209
|
|
|
202
|
-
def cached_function(fn=None, **kwargs):
|
|
210
|
+
def cached_function(fn=None, **kwargs): # noqa
|
|
203
211
|
if fn is None:
|
|
204
212
|
return functools.partial(cached_function, **kwargs)
|
|
205
213
|
opts = _CachedFunction.Opts(**kwargs)
|
|
@@ -209,9 +217,6 @@ def cached_function(fn=None, **kwargs):
|
|
|
209
217
|
return _CachedFunctionDescriptor(fn, scope, opts=opts)
|
|
210
218
|
|
|
211
219
|
|
|
212
|
-
cached_function = cached_function
|
|
213
|
-
|
|
214
|
-
|
|
215
220
|
##
|
|
216
221
|
|
|
217
222
|
|
|
@@ -261,7 +266,7 @@ class _CachedProperty:
|
|
|
261
266
|
raise TypeError(self._name)
|
|
262
267
|
|
|
263
268
|
|
|
264
|
-
def cached_property(fn=None, **kwargs):
|
|
269
|
+
def cached_property(fn=None, **kwargs): # noqa
|
|
265
270
|
if fn is None:
|
|
266
271
|
return functools.partial(cached_property, **kwargs)
|
|
267
272
|
return _CachedProperty(fn, **kwargs)
|
omlish/lang/classes/__init__.py
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
|
-
from .abstract import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
from .restrict import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
from .
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
from .abstract import ( # noqa
|
|
2
|
+
Abstract,
|
|
3
|
+
is_abstract,
|
|
4
|
+
is_abstract_class,
|
|
5
|
+
is_abstract_method,
|
|
6
|
+
make_abstract,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
from .restrict import ( # noqa
|
|
10
|
+
Final,
|
|
11
|
+
FinalError,
|
|
12
|
+
NoBool,
|
|
13
|
+
NotInstantiable,
|
|
14
|
+
NotPicklable,
|
|
15
|
+
PackageSealed,
|
|
16
|
+
Sealed,
|
|
17
|
+
SealedError,
|
|
18
|
+
no_bool,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
from .simple import ( # noqa
|
|
22
|
+
LazySingleton,
|
|
23
|
+
Marker,
|
|
24
|
+
Namespace,
|
|
25
|
+
SimpleMetaDict,
|
|
26
|
+
Singleton,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
from .virtual import ( # noqa
|
|
30
|
+
Callable,
|
|
31
|
+
Descriptor,
|
|
32
|
+
Picklable,
|
|
33
|
+
Virtual,
|
|
34
|
+
virtual_check,
|
|
35
|
+
)
|
omlish/lang/classes/abstract.py
CHANGED
|
@@ -23,7 +23,7 @@ def make_abstract(obj: T) -> T:
|
|
|
23
23
|
return obj
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
class Abstract(abc.ABC):
|
|
26
|
+
class Abstract(abc.ABC): # noqa
|
|
27
27
|
__slots__ = ()
|
|
28
28
|
|
|
29
29
|
def __forceabstract__(self):
|
|
@@ -31,7 +31,7 @@ class Abstract(abc.ABC):
|
|
|
31
31
|
|
|
32
32
|
setattr(__forceabstract__, '__isabstractmethod__', True)
|
|
33
33
|
|
|
34
|
-
def __init_subclass__(cls, **kwargs) -> None:
|
|
34
|
+
def __init_subclass__(cls, **kwargs: ta.Any) -> None:
|
|
35
35
|
if Abstract in cls.__bases__:
|
|
36
36
|
cls.__forceabstract__ = Abstract.__forceabstract__ # type: ignore
|
|
37
37
|
else:
|
|
@@ -48,7 +48,7 @@ class Abstract(abc.ABC):
|
|
|
48
48
|
if ams:
|
|
49
49
|
raise TypeError(
|
|
50
50
|
f'Cannot subclass abstract class {cls.__name__} with abstract methods'
|
|
51
|
-
f'{", ".join(map(str, sorted(ams)))}'
|
|
51
|
+
f'{", ".join(map(str, sorted(ams)))}',
|
|
52
52
|
)
|
|
53
53
|
|
|
54
54
|
|
omlish/lang/classes/restrict.py
CHANGED
|
@@ -8,9 +8,9 @@ from .abstract import is_abstract
|
|
|
8
8
|
##
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
class
|
|
11
|
+
class FinalError(TypeError):
|
|
12
12
|
|
|
13
|
-
def __init__(self, _type:
|
|
13
|
+
def __init__(self, _type: type) -> None:
|
|
14
14
|
super().__init__()
|
|
15
15
|
|
|
16
16
|
self._type = _type
|
|
@@ -22,17 +22,17 @@ class FinalException(TypeError):
|
|
|
22
22
|
class Final(Abstract):
|
|
23
23
|
__slots__ = ()
|
|
24
24
|
|
|
25
|
-
def __init_subclass__(cls, **kwargs) -> None:
|
|
25
|
+
def __init_subclass__(cls, **kwargs: ta.Any) -> None:
|
|
26
26
|
super().__init_subclass__(**kwargs)
|
|
27
27
|
|
|
28
28
|
abstracts: set[ta.Any] = set()
|
|
29
29
|
for base in cls.__bases__:
|
|
30
30
|
if base is Abstract:
|
|
31
|
-
raise
|
|
31
|
+
raise FinalError(base)
|
|
32
32
|
elif base is Final:
|
|
33
33
|
continue
|
|
34
34
|
elif Final in base.__mro__:
|
|
35
|
-
raise
|
|
35
|
+
raise FinalError(base)
|
|
36
36
|
else:
|
|
37
37
|
abstracts.update(getattr(base, '__abstractmethods__', []))
|
|
38
38
|
|
|
@@ -40,15 +40,15 @@ class Final(Abstract):
|
|
|
40
40
|
try:
|
|
41
41
|
v = cls.__dict__[a]
|
|
42
42
|
except KeyError:
|
|
43
|
-
raise
|
|
43
|
+
raise FinalError(a) from None
|
|
44
44
|
if is_abstract(v):
|
|
45
|
-
raise
|
|
45
|
+
raise FinalError(a)
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
##
|
|
49
49
|
|
|
50
50
|
|
|
51
|
-
class
|
|
51
|
+
class SealedError(TypeError):
|
|
52
52
|
|
|
53
53
|
def __init__(self, _type) -> None:
|
|
54
54
|
super().__init__()
|
|
@@ -62,24 +62,24 @@ class SealedException(TypeError):
|
|
|
62
62
|
class Sealed:
|
|
63
63
|
__slots__ = ()
|
|
64
64
|
|
|
65
|
-
def __init_subclass__(cls, **kwargs) -> None:
|
|
65
|
+
def __init_subclass__(cls, **kwargs: ta.Any) -> None:
|
|
66
66
|
for base in cls.__bases__:
|
|
67
67
|
if base is not Abstract:
|
|
68
68
|
if Sealed in base.__bases__:
|
|
69
69
|
if cls.__module__ != base.__module__:
|
|
70
|
-
raise
|
|
70
|
+
raise SealedError(base)
|
|
71
71
|
super().__init_subclass__(**kwargs)
|
|
72
72
|
|
|
73
73
|
|
|
74
74
|
class PackageSealed:
|
|
75
75
|
__slots__ = ()
|
|
76
76
|
|
|
77
|
-
def __init_subclass__(cls, **kwargs) -> None:
|
|
77
|
+
def __init_subclass__(cls, **kwargs: ta.Any) -> None:
|
|
78
78
|
for base in cls.__bases__:
|
|
79
79
|
if base is not Abstract:
|
|
80
80
|
if PackageSealed in base.__bases__:
|
|
81
81
|
if cls.__module__.split('.')[:-1] != base.__module__.split('.')[:-1]:
|
|
82
|
-
raise
|
|
82
|
+
raise SealedError(base)
|
|
83
83
|
super().__init_subclass__(**kwargs)
|
|
84
84
|
|
|
85
85
|
|
|
@@ -89,7 +89,7 @@ class PackageSealed:
|
|
|
89
89
|
class NotInstantiable(Abstract):
|
|
90
90
|
__slots__ = ()
|
|
91
91
|
|
|
92
|
-
def __new__(cls, *args, **kwargs) -> ta.NoReturn:
|
|
92
|
+
def __new__(cls, *args: ta.Any, **kwargs: ta.Any) -> ta.NoReturn: # noqa
|
|
93
93
|
raise TypeError
|
|
94
94
|
|
|
95
95
|
|
|
@@ -133,5 +133,5 @@ class _NoBoolDescriptor:
|
|
|
133
133
|
return self._fn(*args, **kwargs)
|
|
134
134
|
|
|
135
135
|
|
|
136
|
-
def no_bool(fn):
|
|
136
|
+
def no_bool(fn): # noqa
|
|
137
137
|
return _NoBoolDescriptor(fn)
|
omlish/lang/classes/simple.py
CHANGED
|
@@ -26,7 +26,7 @@ Namespace: type = _Namespace() # type: ignore
|
|
|
26
26
|
##
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
_MARKER_NAMESPACE_KEYS:
|
|
29
|
+
_MARKER_NAMESPACE_KEYS: set[str] | None = None
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
class _MarkerMeta(abc.ABCMeta):
|
|
@@ -100,7 +100,7 @@ class Singleton:
|
|
|
100
100
|
def __new__(cls):
|
|
101
101
|
return cls.__dict__[_SINGLETON_INSTANCE_ATTR]
|
|
102
102
|
|
|
103
|
-
def __init_subclass__(cls, **kwargs):
|
|
103
|
+
def __init_subclass__(cls, **kwargs: ta.Any) -> None:
|
|
104
104
|
super().__init_subclass__(**kwargs)
|
|
105
105
|
_set_singleton_instance(super().__new__(cls)) # noqa
|
|
106
106
|
|
omlish/lang/classes/virtual.py
CHANGED
|
@@ -15,10 +15,10 @@ Ty = ta.TypeVar('Ty', bound=type)
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
def _make_not_instantiable():
|
|
18
|
-
def __new__(cls, *args, **kwargs):
|
|
18
|
+
def __new__(cls, *args, **kwargs): # noqa
|
|
19
19
|
raise TypeError(cls)
|
|
20
20
|
|
|
21
|
-
def __init__(self, *args, **kwargs):
|
|
21
|
+
def __init__(self, *args, **kwargs): # noqa
|
|
22
22
|
raise TypeError(self)
|
|
23
23
|
|
|
24
24
|
return {
|
|
@@ -49,7 +49,7 @@ class _VirtualMeta(abc.ABCMeta):
|
|
|
49
49
|
reqset -= set(mro_cls.__dict__)
|
|
50
50
|
return reqset
|
|
51
51
|
|
|
52
|
-
def __subclasshook__(cls, subclass):
|
|
52
|
+
def __subclasshook__(cls, subclass): # noqa
|
|
53
53
|
if cls is not kls:
|
|
54
54
|
return super(kls, cls).__subclasshook__(subclass) # type: ignore
|
|
55
55
|
if get_missing_reqs(subclass):
|
|
@@ -117,11 +117,11 @@ class Callable(NotInstantiable, Final, ta.Generic[T]):
|
|
|
117
117
|
raise TypeError
|
|
118
118
|
|
|
119
119
|
@classmethod
|
|
120
|
-
def __instancecheck__(cls, instance):
|
|
120
|
+
def __instancecheck__(cls, instance: object) -> bool:
|
|
121
121
|
return callable(instance)
|
|
122
122
|
|
|
123
123
|
@classmethod
|
|
124
|
-
def __subclasscheck__(cls, subclass):
|
|
124
|
+
def __subclasscheck__(cls, subclass: type) -> bool:
|
|
125
125
|
if not hasattr(subclass, '__call__'):
|
|
126
126
|
return False
|
|
127
127
|
call = subclass.__call__
|
omlish/lang/clsdct.py
CHANGED
|
@@ -37,7 +37,7 @@ def get_caller_cls_dct(offset: int = 0) -> ta.MutableMapping[str, ta.Any]:
|
|
|
37
37
|
|
|
38
38
|
class ClassDctFn:
|
|
39
39
|
|
|
40
|
-
def __init__(self, fn: ta.Callable, offset:
|
|
40
|
+
def __init__(self, fn: ta.Callable, offset: int | None = None, *, wrap=True) -> None:
|
|
41
41
|
super().__init__()
|
|
42
42
|
|
|
43
43
|
self._fn = fn
|
|
@@ -60,7 +60,7 @@ class ClassDctFn:
|
|
|
60
60
|
return self._fn(cls_dct, *args, **kwargs)
|
|
61
61
|
|
|
62
62
|
|
|
63
|
-
def cls_dct_fn(offset=1, *, wrap=True):
|
|
63
|
+
def cls_dct_fn(offset=1, *, wrap=True): # noqa
|
|
64
64
|
def outer(fn):
|
|
65
65
|
return ClassDctFn(fn, offset, wrap=wrap)
|
|
66
66
|
|
omlish/lang/cmp.py
CHANGED
|
@@ -18,7 +18,7 @@ class InfinityType:
|
|
|
18
18
|
def __le__(self, other: ta.Any) -> bool:
|
|
19
19
|
return False
|
|
20
20
|
|
|
21
|
-
def __eq__(self, other:
|
|
21
|
+
def __eq__(self, other: object) -> bool:
|
|
22
22
|
return isinstance(other, self.__class__)
|
|
23
23
|
|
|
24
24
|
def __gt__(self, other: ta.Any) -> bool:
|
|
@@ -47,7 +47,7 @@ class NegativeInfinityType:
|
|
|
47
47
|
def __le__(self, other: ta.Any) -> bool:
|
|
48
48
|
return True
|
|
49
49
|
|
|
50
|
-
def __eq__(self, other:
|
|
50
|
+
def __eq__(self, other: object) -> bool:
|
|
51
51
|
return isinstance(other, self.__class__)
|
|
52
52
|
|
|
53
53
|
def __gt__(self, other: ta.Any) -> bool:
|