omlish 0.0.0.dev340__py3-none-any.whl → 0.0.0.dev341__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/check.py +197 -30
- omlish/lite/check.py +6 -6
- omlish/typedvalues/__init__.py +4 -0
- omlish/typedvalues/collection.py +3 -0
- omlish/typedvalues/consumer.py +12 -0
- {omlish-0.0.0.dev340.dist-info → omlish-0.0.0.dev341.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev340.dist-info → omlish-0.0.0.dev341.dist-info}/RECORD +12 -12
- {omlish-0.0.0.dev340.dist-info → omlish-0.0.0.dev341.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev340.dist-info → omlish-0.0.0.dev341.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev340.dist-info → omlish-0.0.0.dev341.dist-info}/licenses/LICENSE +0 -0
- {omlish-0.0.0.dev340.dist-info → omlish-0.0.0.dev341.dist-info}/top_level.txt +0 -0
omlish/__about__.py
CHANGED
omlish/check.py
CHANGED
@@ -14,6 +14,10 @@ from .lite.check import Checks
|
|
14
14
|
from .lite.check import check
|
15
15
|
|
16
16
|
|
17
|
+
T = ta.TypeVar('T')
|
18
|
+
SizedT = ta.TypeVar('SizedT', bound=ta.Sized)
|
19
|
+
|
20
|
+
|
17
21
|
_isinstance = isinstance
|
18
22
|
_issubclass = issubclass
|
19
23
|
_callable = callable
|
@@ -22,8 +26,12 @@ _callable = callable
|
|
22
26
|
##
|
23
27
|
|
24
28
|
|
25
|
-
register_on_raise
|
26
|
-
|
29
|
+
def register_on_raise(fn: OnRaiseFn) -> None:
|
30
|
+
check.register_on_raise(fn)
|
31
|
+
|
32
|
+
|
33
|
+
def unregister_on_raise(fn: OnRaiseFn) -> None:
|
34
|
+
check.unregister_on_raise(fn)
|
27
35
|
|
28
36
|
|
29
37
|
##
|
@@ -57,48 +65,207 @@ check.register_late_configure(_try_enable_args_rendering)
|
|
57
65
|
|
58
66
|
|
59
67
|
##
|
68
|
+
# The following code manually proxies to the lite code, as opposed to simply assigning global names to instance methods
|
69
|
+
# of `check`, to assist type analysis in tools - pycharm for example has a hard time deducing the return types in such
|
70
|
+
# cases. The functions are however dynamically overwritten below with direct references to the method to remove one
|
71
|
+
# layer of call indirection at runtime.
|
72
|
+
|
73
|
+
|
74
|
+
_CHECK_PROXY_FUNCTIONS: dict[str, ta.Any] = {}
|
75
|
+
|
76
|
+
|
77
|
+
def _check_proxy_function(fn: T) -> T:
|
78
|
+
name = fn.__name__ # type: ignore[attr-defined]
|
79
|
+
if name in _CHECK_PROXY_FUNCTIONS:
|
80
|
+
raise NameError(fn)
|
81
|
+
_CHECK_PROXY_FUNCTIONS[name] = fn
|
82
|
+
return fn
|
83
|
+
|
84
|
+
|
85
|
+
##
|
86
|
+
|
87
|
+
|
88
|
+
@ta.overload
|
89
|
+
def isinstance(v: ta.Any, spec: type[T], msg: Message = None) -> T: # noqa
|
90
|
+
...
|
91
|
+
|
92
|
+
|
93
|
+
@ta.overload
|
94
|
+
def isinstance(v: ta.Any, spec: ta.Any, msg: Message = None) -> ta.Any: # noqa
|
95
|
+
...
|
96
|
+
|
97
|
+
|
98
|
+
@_check_proxy_function
|
99
|
+
def isinstance(v, spec, msg=None): # noqa
|
100
|
+
return check.isinstance(v, spec, msg=msg)
|
101
|
+
|
102
|
+
|
103
|
+
@ta.overload
|
104
|
+
def of_isinstance(spec: type[T], msg: Message = None) -> ta.Callable[[ta.Any], T]:
|
105
|
+
...
|
106
|
+
|
60
107
|
|
108
|
+
@ta.overload
|
109
|
+
def of_isinstance(spec: ta.Any, msg: Message = None) -> ta.Callable[[ta.Any], ta.Any]:
|
110
|
+
...
|
111
|
+
|
112
|
+
|
113
|
+
@_check_proxy_function
|
114
|
+
def of_isinstance(spec, msg=None):
|
115
|
+
return check.of_isinstance(spec, msg=msg)
|
116
|
+
|
117
|
+
|
118
|
+
@_check_proxy_function
|
119
|
+
def cast(v: ta.Any, cls: type[T], msg: Message = None) -> T:
|
120
|
+
return check.cast(v, cls, msg=msg)
|
121
|
+
|
122
|
+
|
123
|
+
@_check_proxy_function
|
124
|
+
def of_cast(cls: type[T], msg: Message = None) -> ta.Callable[[T], T]:
|
125
|
+
return check.of_cast(cls, msg=msg)
|
126
|
+
|
127
|
+
|
128
|
+
@_check_proxy_function
|
129
|
+
def not_isinstance(v: T, spec: ta.Any, msg: Message = None) -> T:
|
130
|
+
return check.not_isinstance(v, spec, msg=msg)
|
131
|
+
|
132
|
+
|
133
|
+
@_check_proxy_function
|
134
|
+
def of_not_isinstance(spec: ta.Any, msg: Message = None) -> ta.Callable[[T], T]:
|
135
|
+
return check.of_not_isinstance(spec, msg=msg)
|
61
136
|
|
62
|
-
isinstance = check.isinstance # noqa
|
63
|
-
of_isinstance = check.of_isinstance
|
64
|
-
cast = check.cast
|
65
|
-
of_cast = check.of_cast
|
66
|
-
not_isinstance = check.not_isinstance
|
67
|
-
of_not_isinstance = check.of_not_isinstance
|
68
137
|
|
69
138
|
#
|
70
139
|
|
71
|
-
|
72
|
-
|
140
|
+
|
141
|
+
@_check_proxy_function
|
142
|
+
def issubclass(v: type[T], spec: ta.Any, msg: Message = None) -> type[T]: # noqa
|
143
|
+
return check.issubclass(v, spec, msg=msg)
|
144
|
+
|
145
|
+
|
146
|
+
@_check_proxy_function
|
147
|
+
def not_issubclass(v: type[T], spec: ta.Any, msg: Message = None) -> type[T]:
|
148
|
+
return check.not_issubclass(v, spec, msg=msg)
|
149
|
+
|
73
150
|
|
74
151
|
#
|
75
152
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
153
|
+
|
154
|
+
@_check_proxy_function
|
155
|
+
def in_(v: T, c: ta.Container[T], msg: Message = None) -> T:
|
156
|
+
return check.in_(v, c, msg=msg)
|
157
|
+
|
158
|
+
|
159
|
+
@_check_proxy_function
|
160
|
+
def not_in(v: T, c: ta.Container[T], msg: Message = None) -> T:
|
161
|
+
return check.not_in(v, c, msg=msg)
|
162
|
+
|
163
|
+
|
164
|
+
@_check_proxy_function
|
165
|
+
def empty(v: SizedT, msg: Message = None) -> SizedT:
|
166
|
+
return check.empty(v, msg=msg)
|
167
|
+
|
168
|
+
|
169
|
+
@_check_proxy_function
|
170
|
+
def iterempty(v: ta.Iterable[T], msg: Message = None) -> ta.Iterable[T]:
|
171
|
+
return check.iterempty(v, msg=msg)
|
172
|
+
|
173
|
+
|
174
|
+
@_check_proxy_function
|
175
|
+
def not_empty(v: SizedT, msg: Message = None) -> SizedT:
|
176
|
+
return check.not_empty(v, msg=msg)
|
177
|
+
|
178
|
+
|
179
|
+
@_check_proxy_function
|
180
|
+
def unique(it: ta.Iterable[T], msg: Message = None) -> ta.Iterable[T]:
|
181
|
+
return check.unique(it, msg=msg)
|
182
|
+
|
183
|
+
|
184
|
+
@_check_proxy_function
|
185
|
+
def single(obj: ta.Iterable[T], msg: Message = None) -> T:
|
186
|
+
return check.single(obj, msg=msg)
|
187
|
+
|
188
|
+
|
189
|
+
@_check_proxy_function
|
190
|
+
def opt_single(obj: ta.Iterable[T], msg: Message = None) -> T | None:
|
191
|
+
return check.opt_single(obj, msg=msg)
|
192
|
+
|
84
193
|
|
85
194
|
#
|
86
195
|
|
87
|
-
|
88
|
-
|
196
|
+
|
197
|
+
@_check_proxy_function
|
198
|
+
def none(v: ta.Any, msg: Message = None) -> None:
|
199
|
+
return check.none(v, msg=msg)
|
200
|
+
|
201
|
+
|
202
|
+
@_check_proxy_function
|
203
|
+
def not_none(v: T | None, msg: Message = None) -> T:
|
204
|
+
return check.not_none(v, msg=msg)
|
205
|
+
|
89
206
|
|
90
207
|
#
|
91
208
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
209
|
+
|
210
|
+
@_check_proxy_function
|
211
|
+
def equal(v: T, o: ta.Any, msg: Message = None) -> T:
|
212
|
+
return check.equal(v, o, msg=msg)
|
213
|
+
|
214
|
+
|
215
|
+
@_check_proxy_function
|
216
|
+
def not_equal(v: T, o: ta.Any, msg: Message = None) -> T:
|
217
|
+
return check.not_equal(v, o, msg=msg)
|
218
|
+
|
219
|
+
|
220
|
+
@_check_proxy_function
|
221
|
+
def is_(v: T, o: ta.Any, msg: Message = None) -> T:
|
222
|
+
return check.is_(v, o, msg=msg)
|
223
|
+
|
224
|
+
|
225
|
+
@_check_proxy_function
|
226
|
+
def is_not(v: T, o: ta.Any, msg: Message = None) -> T:
|
227
|
+
return check.is_not(v, o, msg=msg)
|
228
|
+
|
229
|
+
|
230
|
+
@_check_proxy_function
|
231
|
+
def callable(v: T, msg: Message = None) -> T: # noqa
|
232
|
+
return check.callable(v, msg=msg)
|
233
|
+
|
234
|
+
|
235
|
+
@_check_proxy_function
|
236
|
+
def non_empty_str(v: str | None, msg: Message = None) -> str:
|
237
|
+
return check.non_empty_str(v, msg=msg)
|
238
|
+
|
239
|
+
|
240
|
+
@_check_proxy_function
|
241
|
+
def replacing(expected: ta.Any, old: ta.Any, new: T, msg: Message = None) -> T:
|
242
|
+
return check.replacing(expected, old, new, msg=msg)
|
243
|
+
|
244
|
+
|
245
|
+
@_check_proxy_function
|
246
|
+
def replacing_none(old: ta.Any, new: T, msg: Message = None) -> T:
|
247
|
+
return check.replacing_none(old, new, msg=msg)
|
248
|
+
|
100
249
|
|
101
250
|
#
|
102
251
|
|
103
|
-
|
104
|
-
|
252
|
+
|
253
|
+
@_check_proxy_function
|
254
|
+
def arg(v: bool, msg: Message = None) -> None:
|
255
|
+
return check.arg(v, msg=msg)
|
256
|
+
|
257
|
+
|
258
|
+
@_check_proxy_function
|
259
|
+
def state(v: bool, msg: Message = None) -> None:
|
260
|
+
return check.state(v, msg=msg)
|
261
|
+
|
262
|
+
|
263
|
+
##
|
264
|
+
|
265
|
+
|
266
|
+
def _install_direct_check_proxy_functions() -> None:
|
267
|
+
for n in _CHECK_PROXY_FUNCTIONS:
|
268
|
+
globals()[n] = getattr(check, n)
|
269
|
+
|
270
|
+
|
271
|
+
_install_direct_check_proxy_functions()
|
omlish/lite/check.py
CHANGED
@@ -177,7 +177,7 @@ class Checks:
|
|
177
177
|
|
178
178
|
return inner
|
179
179
|
|
180
|
-
def cast(self, v: ta.Any, cls: ta.Type[T], msg: CheckMessage = None) -> T:
|
180
|
+
def cast(self, v: ta.Any, cls: ta.Type[T], msg: CheckMessage = None) -> T:
|
181
181
|
if not isinstance(v, cls):
|
182
182
|
self._raise(
|
183
183
|
TypeError,
|
@@ -226,7 +226,7 @@ class Checks:
|
|
226
226
|
|
227
227
|
return v
|
228
228
|
|
229
|
-
def not_issubclass(self, v: ta.Type[T], spec: ta.Any, msg: CheckMessage = None) -> ta.Type[T]:
|
229
|
+
def not_issubclass(self, v: ta.Type[T], spec: ta.Any, msg: CheckMessage = None) -> ta.Type[T]:
|
230
230
|
if issubclass(v, spec):
|
231
231
|
self._raise(
|
232
232
|
TypeError,
|
@@ -317,21 +317,21 @@ class Checks:
|
|
317
317
|
|
318
318
|
return it
|
319
319
|
|
320
|
-
def single(self, obj: ta.Iterable[T],
|
320
|
+
def single(self, obj: ta.Iterable[T], msg: CheckMessage = None) -> T:
|
321
321
|
try:
|
322
322
|
[value] = obj
|
323
323
|
except ValueError:
|
324
324
|
self._raise(
|
325
325
|
ValueError,
|
326
326
|
'Must be single',
|
327
|
-
|
327
|
+
msg,
|
328
328
|
Checks._ArgsKwargs(obj),
|
329
329
|
render_fmt='%s',
|
330
330
|
)
|
331
331
|
|
332
332
|
return value
|
333
333
|
|
334
|
-
def opt_single(self, obj: ta.Iterable[T],
|
334
|
+
def opt_single(self, obj: ta.Iterable[T], msg: CheckMessage = None) -> ta.Optional[T]:
|
335
335
|
it = iter(obj)
|
336
336
|
try:
|
337
337
|
value = next(it)
|
@@ -346,7 +346,7 @@ class Checks:
|
|
346
346
|
self._raise(
|
347
347
|
ValueError,
|
348
348
|
'Must be empty or single',
|
349
|
-
|
349
|
+
msg,
|
350
350
|
Checks._ArgsKwargs(obj),
|
351
351
|
render_fmt='%s',
|
352
352
|
)
|
omlish/typedvalues/__init__.py
CHANGED
@@ -6,12 +6,16 @@ from .collection import ( # noqa
|
|
6
6
|
DuplicateUniqueTypedValueError,
|
7
7
|
|
8
8
|
TypedValues,
|
9
|
+
|
10
|
+
collect,
|
9
11
|
)
|
10
12
|
|
11
13
|
from .consumer import ( # noqa
|
12
14
|
UnconsumedTypedValuesError,
|
13
15
|
|
14
16
|
TypedValuesConsumer,
|
17
|
+
|
18
|
+
consume,
|
15
19
|
)
|
16
20
|
|
17
21
|
from .generic import ( # noqa
|
omlish/typedvalues/collection.py
CHANGED
omlish/typedvalues/consumer.py
CHANGED
@@ -173,3 +173,15 @@ class TypedValuesConsumer(ta.Generic[TypedValueT]):
|
|
173
173
|
continue
|
174
174
|
dct[k] = v.v # type: ignore[attr-defined]
|
175
175
|
return dct
|
176
|
+
|
177
|
+
|
178
|
+
def consume(
|
179
|
+
*tvs: TypedValueT,
|
180
|
+
override: bool = False,
|
181
|
+
check_type: type | tuple[type, ...] | None = None,
|
182
|
+
) -> TypedValuesConsumer[TypedValueT]:
|
183
|
+
return tvc.TypedValues(
|
184
|
+
*tvs,
|
185
|
+
override=override,
|
186
|
+
check_type=check_type,
|
187
|
+
).consume()
|
@@ -1,9 +1,9 @@
|
|
1
1
|
omlish/.manifests.json,sha256=orgsRvtpHu8tdhaCvlP9v3P495OJopYYiHKjK68WtWg,8587
|
2
|
-
omlish/__about__.py,sha256
|
2
|
+
omlish/__about__.py,sha256=-wUi4yRsm8-Vl2E8pqCgJ01xximlfoHOUxwGIw70mHQ,3478
|
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
|
6
|
-
omlish/check.py,sha256=
|
6
|
+
omlish/check.py,sha256=DDNZnLxNoY2Y7N0Hz7nMR1q912ZzRLoBgOJVLcsXVws,6575
|
7
7
|
omlish/datetimes.py,sha256=iFqCki3MKmBq_ZX-03cW4KE6AsR_pUJCWML2ifBLtdU,2157
|
8
8
|
omlish/defs.py,sha256=-4UuZoJUUNO_bZ6eSSdhR4CK4NKN2Wwr1FfUvfTF--8,4918
|
9
9
|
omlish/dynamic.py,sha256=zy0oO70_Vlh5dW8Nwav_O9bhIzQ6L16UgSuKR6y43VU,6526
|
@@ -449,7 +449,7 @@ omlish/lifecycles/states.py,sha256=zqMOU2ZU-MDNnWuwauM3_anIAiXM8LoBDElDEraptFg,1
|
|
449
449
|
omlish/lifecycles/transitions.py,sha256=qQtFby-h4VzbvgaUqT2NnbNumlcOx9FVVADP9t83xj4,1939
|
450
450
|
omlish/lite/__init__.py,sha256=ISLhM4q0LR1XXTCaHdZOZxBRyIsoZqYm4u0bf1BPcVk,148
|
451
451
|
omlish/lite/cached.py,sha256=O7ozcoDNFm1Hg2wtpHEqYSp_i_nCLNOP6Ueq_Uk-7mU,1300
|
452
|
-
omlish/lite/check.py,sha256=
|
452
|
+
omlish/lite/check.py,sha256=Mqp-0Ky8WKuut0aNVR4Nfjw2QQ7GunI3cMfLR-nLNXI,13854
|
453
453
|
omlish/lite/configs.py,sha256=Ev_19sbII67pTWzInYjYqa9VyTiZBvyjhZqyG8TtufE,908
|
454
454
|
omlish/lite/contextmanagers.py,sha256=WrL2NPT7OA5JvHp4H-opwsCpYTHod27EJ4qB1cJ9Mjc,5691
|
455
455
|
omlish/lite/dataclasses.py,sha256=t1G5-xOuvE6o6w9RyqHzLT9wHD0HkqBh5P8HUZWxGzs,1912
|
@@ -854,19 +854,19 @@ omlish/text/antlr/_runtime/xpath/XPathLexer.py,sha256=WvGKQjQnu7pX5C4CFKtsCzba2B
|
|
854
854
|
omlish/text/antlr/_runtime/xpath/__init__.py,sha256=lMd_BbXYdlDhZQN_q0TKN978XW5G0pq618F0NaLkpFE,71
|
855
855
|
omlish/text/go/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
856
856
|
omlish/text/go/quoting.py,sha256=N9EYdnFdEX_A8fOviH-1w4jwV3XOQ7VU2WsoUNubYVY,9137
|
857
|
-
omlish/typedvalues/__init__.py,sha256=
|
857
|
+
omlish/typedvalues/__init__.py,sha256=Un8i5o0H27H8ruU4kHh3SDv_jxZQEyHEkSYahHkmRag,750
|
858
858
|
omlish/typedvalues/accessor.py,sha256=959QsdK1zildcBTvFKSA6uAgi7SSo2RPKqcKWsuEZrM,3162
|
859
|
-
omlish/typedvalues/collection.py,sha256=
|
860
|
-
omlish/typedvalues/consumer.py,sha256=
|
859
|
+
omlish/typedvalues/collection.py,sha256=3FdR2x7fJiVnozbu5df0Lh6C9JSYo6Ofke9CjVFcOCA,5595
|
860
|
+
omlish/typedvalues/consumer.py,sha256=Apw1s7eedbKeTNMk5BITCJISA_7hPNqi2tWK15g3e1M,4651
|
861
861
|
omlish/typedvalues/generic.py,sha256=ft-x4X3k1oFirtYnDfsvrI3ZQikWM8lGLrvrOEbcGq0,742
|
862
862
|
omlish/typedvalues/holder.py,sha256=vu-umn-h1nvUqmtV5T9ZfQ_OoOYsERu8PhI2N48Ryns,1133
|
863
863
|
omlish/typedvalues/marshal.py,sha256=AtBz7Jq-BfW8vwM7HSxSpR85JAXmxK2T0xDblmm1HI0,4956
|
864
864
|
omlish/typedvalues/of_.py,sha256=UXkxSj504WI2UrFlqdZJbu2hyDwBhL7XVrc2qdR02GQ,1309
|
865
865
|
omlish/typedvalues/reflect.py,sha256=PAvKW6T4cW7u--iX80w3HWwZUS3SmIZ2_lQjT65uAyk,1026
|
866
866
|
omlish/typedvalues/values.py,sha256=ym46I-q2QJ_6l4UlERqv3yj87R-kp8nCKMRph0xQ3UA,1307
|
867
|
-
omlish-0.0.0.
|
868
|
-
omlish-0.0.0.
|
869
|
-
omlish-0.0.0.
|
870
|
-
omlish-0.0.0.
|
871
|
-
omlish-0.0.0.
|
872
|
-
omlish-0.0.0.
|
867
|
+
omlish-0.0.0.dev341.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
|
868
|
+
omlish-0.0.0.dev341.dist-info/METADATA,sha256=VeutF_8EEUirW08HJaddP6XaLvwqbxnG6IAkuBCE3AU,4416
|
869
|
+
omlish-0.0.0.dev341.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
870
|
+
omlish-0.0.0.dev341.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
|
871
|
+
omlish-0.0.0.dev341.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
|
872
|
+
omlish-0.0.0.dev341.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|