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 CHANGED
@@ -1,5 +1,5 @@
1
- __version__ = '0.0.0.dev340'
2
- __revision__ = 'de9a88b0e8d5578e5348e4f23db01e09dd3ebbd0'
1
+ __version__ = '0.0.0.dev341'
2
+ __revision__ = '4154c2c5976e0a4a31e0d9647362a710be0805fa'
3
3
 
4
4
 
5
5
  #
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 = check.register_on_raise
26
- unregister_on_raise = check.unregister_on_raise
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
- issubclass = check.issubclass # noqa
72
- not_issubclass = check.not_issubclass
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
- in_ = check.in_
77
- not_in = check.not_in
78
- empty = check.empty
79
- iterempty = check.iterempty
80
- not_empty = check.not_empty
81
- unique = check.unique
82
- single = check.single
83
- opt_single = check.opt_single
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
- none = check.none
88
- not_none = check.not_none
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
- equal = check.equal
93
- not_equal = check.not_equal
94
- is_ = check.is_
95
- is_not = check.is_not
96
- callable = check.callable # noqa
97
- non_empty_str = check.non_empty_str
98
- replacing = check.replacing
99
- replacing_none = check.replacing_none
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
- arg = check.arg
104
- state = check.state
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: # noqa
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]: # noqa
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], message: CheckMessage = None) -> 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
- message,
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], message: CheckMessage = None) -> ta.Optional[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
- message,
349
+ msg,
350
350
  Checks._ArgsKwargs(obj),
351
351
  render_fmt='%s',
352
352
  )
@@ -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
@@ -205,3 +205,6 @@ class TypedValues(
205
205
  ret = tuple(tv for tv in self if isinstance(tv, cls))
206
206
  any_dct[cls] = ret
207
207
  return ret
208
+
209
+
210
+ collect = TypedValues
@@ -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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: omlish
3
- Version: 0.0.0.dev340
3
+ Version: 0.0.0.dev341
4
4
  Summary: omlish
5
5
  Author: wrmsr
6
6
  License: BSD-3-Clause
@@ -1,9 +1,9 @@
1
1
  omlish/.manifests.json,sha256=orgsRvtpHu8tdhaCvlP9v3P495OJopYYiHKjK68WtWg,8587
2
- omlish/__about__.py,sha256=6UJoYTHXIFWagDFn93wfY_32T-1b-9-HV7hM8VXYLNE,3478
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=VcvqYk3lbxUx3zmbln9tCQsyahTXck0Mg4nIPy-DdOc,2383
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=d3622_iX19iAL-B9QtucLbAt7Z0cZAvJEHOJBVhg3Og,13886
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=Br1vFbV-dEjAfBbZ9Zg2xCGO87U6kduxxq69lrMRODw,722
857
+ omlish/typedvalues/__init__.py,sha256=Un8i5o0H27H8ruU4kHh3SDv_jxZQEyHEkSYahHkmRag,750
858
858
  omlish/typedvalues/accessor.py,sha256=959QsdK1zildcBTvFKSA6uAgi7SSo2RPKqcKWsuEZrM,3162
859
- omlish/typedvalues/collection.py,sha256=QxQwaSmJGF2oAWAv2CZkgpOljbnxor104XOrCD0v1a8,5571
860
- omlish/typedvalues/consumer.py,sha256=peDQAgriSyBx_Hc8QHAhEgYy0oSS52qQ_7Tqdssl2AE,4375
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.dev340.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
868
- omlish-0.0.0.dev340.dist-info/METADATA,sha256=C8Px98rFp8jX4oXUDcpPH5CJ5UFR9qVA5TcDjeu07KA,4416
869
- omlish-0.0.0.dev340.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
870
- omlish-0.0.0.dev340.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
871
- omlish-0.0.0.dev340.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
872
- omlish-0.0.0.dev340.dist-info/RECORD,,
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,,