omlish 0.0.0.dev453__py3-none-any.whl → 0.0.0.dev455__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/collections/identity.py +1 -0
- omlish/dataclasses/__init__.py +2 -0
- omlish/funcs/guard.py +27 -16
- omlish/lang/__init__.py +1 -0
- omlish/lang/functions.py +2 -2
- omlish/lang/iterables.py +8 -0
- omlish/lite/attrops.py +2 -0
- omlish/lite/dataclasses.py +30 -0
- omlish/marshal/__init__.py +16 -11
- omlish/marshal/base/contexts.py +33 -20
- omlish/marshal/base/funcs.py +8 -11
- omlish/marshal/base/options.py +8 -0
- omlish/marshal/base/types.py +38 -14
- omlish/marshal/composite/iterables.py +33 -20
- omlish/marshal/composite/literals.py +16 -18
- omlish/marshal/composite/mappings.py +36 -23
- omlish/marshal/composite/maybes.py +29 -19
- omlish/marshal/composite/newtypes.py +16 -16
- omlish/marshal/composite/optionals.py +14 -14
- omlish/marshal/composite/special.py +15 -15
- omlish/marshal/composite/unions/__init__.py +0 -0
- omlish/marshal/composite/unions/literals.py +93 -0
- omlish/marshal/composite/unions/primitives.py +103 -0
- omlish/marshal/factories/invalidate.py +18 -68
- omlish/marshal/factories/method.py +26 -0
- omlish/marshal/factories/moduleimport/factories.py +15 -56
- omlish/marshal/factories/multi.py +13 -25
- omlish/marshal/factories/recursive.py +42 -56
- omlish/marshal/factories/typecache.py +20 -77
- omlish/marshal/factories/typemap.py +42 -43
- omlish/marshal/objects/dataclasses.py +129 -106
- omlish/marshal/objects/marshal.py +18 -14
- omlish/marshal/objects/namedtuples.py +48 -42
- omlish/marshal/objects/unmarshal.py +19 -15
- omlish/marshal/polymorphism/marshal.py +9 -11
- omlish/marshal/polymorphism/unions.py +17 -11
- omlish/marshal/polymorphism/unmarshal.py +9 -10
- omlish/marshal/singular/enums.py +14 -18
- omlish/marshal/standard.py +8 -8
- omlish/marshal/trivial/any.py +1 -1
- omlish/marshal/trivial/forbidden.py +21 -26
- omlish/os/forkhooks.py +4 -0
- omlish/specs/jsonrpc/_marshal.py +33 -24
- omlish/specs/openapi/_marshal.py +30 -21
- omlish/typedvalues/marshal.py +83 -57
- {omlish-0.0.0.dev453.dist-info → omlish-0.0.0.dev455.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev453.dist-info → omlish-0.0.0.dev455.dist-info}/RECORD +52 -52
- omlish/funcs/match.py +0 -229
- omlish/marshal/composite/unions.py +0 -213
- omlish/marshal/factories/match.py +0 -34
- omlish/marshal/factories/simple.py +0 -28
- {omlish-0.0.0.dev453.dist-info → omlish-0.0.0.dev455.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev453.dist-info → omlish-0.0.0.dev455.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev453.dist-info → omlish-0.0.0.dev455.dist-info}/licenses/LICENSE +0 -0
- {omlish-0.0.0.dev453.dist-info → omlish-0.0.0.dev455.dist-info}/top_level.txt +0 -0
omlish/typedvalues/marshal.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
import typing as ta
|
2
|
+
|
1
3
|
from .. import check
|
2
4
|
from .. import dataclasses as dc
|
3
5
|
from .. import lang
|
4
6
|
from .. import marshal as msh
|
5
7
|
from .. import reflect as rfl
|
6
|
-
from ..funcs import match as mfs
|
7
8
|
from .collection import TypedValues
|
8
9
|
from .reflect import reflect_typed_values_impls
|
9
10
|
from .values import ScalarTypedValue
|
@@ -14,7 +15,7 @@ from .values import TypedValue
|
|
14
15
|
|
15
16
|
|
16
17
|
def _build_typed_value_poly(rty: rfl.Type) -> msh.Polymorphism:
|
17
|
-
ty: type[TypedValue] = check.issubclass(check.isinstance(rty, type), TypedValue)
|
18
|
+
ty: type[TypedValue] = check.issubclass(check.isinstance(rty, type), TypedValue) # noqa
|
18
19
|
check.state(lang.is_abstract_class(ty))
|
19
20
|
return msh.polymorphism_from_subclasses(
|
20
21
|
ty,
|
@@ -23,51 +24,68 @@ def _build_typed_value_poly(rty: rfl.Type) -> msh.Polymorphism:
|
|
23
24
|
)
|
24
25
|
|
25
26
|
|
26
|
-
class TypedValueMarshalerFactory(msh.
|
27
|
-
@
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
27
|
+
class TypedValueMarshalerFactory(msh.MarshalerFactoryMethodClass):
|
28
|
+
@msh.MarshalerFactoryMethodClass.make_marshaler.register
|
29
|
+
def _make_scalar(self, ctx: msh.MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], msh.Marshaler] | None:
|
30
|
+
if not (
|
31
|
+
isinstance(rty, type) and
|
32
|
+
issubclass(rty, ScalarTypedValue) and
|
33
|
+
not lang.is_abstract_class(rty)
|
34
|
+
):
|
35
|
+
return None
|
36
|
+
|
37
|
+
def inner() -> msh.Marshaler:
|
38
|
+
dc_rfl = dc.reflect(check.isinstance(rty, type))
|
39
|
+
v_rty = check.single(dc_rfl.fields_inspection.generic_replaced_field_annotations.values())
|
40
|
+
v_m = ctx.make_marshaler(v_rty)
|
41
|
+
return msh.WrappedMarshaler(lambda _, o: o.v, v_m)
|
42
|
+
|
43
|
+
return inner
|
44
|
+
|
45
|
+
@msh.MarshalerFactoryMethodClass.make_marshaler.register
|
46
|
+
def _make_abstract(self, ctx: msh.MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], msh.Marshaler] | None:
|
47
|
+
if not (
|
48
|
+
isinstance(rty, type) and
|
49
|
+
issubclass(rty, TypedValue) and
|
50
|
+
lang.is_abstract_class(rty)
|
51
|
+
):
|
52
|
+
return None
|
53
|
+
|
54
|
+
return lambda: msh.make_polymorphism_marshaler(
|
45
55
|
_build_typed_value_poly(rty).impls,
|
46
56
|
msh.WrapperTypeTagging(),
|
47
57
|
ctx,
|
48
58
|
)
|
49
59
|
|
50
60
|
|
51
|
-
class TypedValueUnmarshalerFactory(msh.
|
52
|
-
@
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
61
|
+
class TypedValueUnmarshalerFactory(msh.UnmarshalerFactoryMethodClass):
|
62
|
+
@msh.UnmarshalerFactoryMethodClass.make_unmarshaler.register
|
63
|
+
def _make_scalar(self, ctx: msh.UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], msh.Unmarshaler] | None:
|
64
|
+
if not (
|
65
|
+
isinstance(rty, type) and
|
66
|
+
issubclass(rty, ScalarTypedValue) and
|
67
|
+
not lang.is_abstract_class(rty)
|
68
|
+
):
|
69
|
+
return None
|
70
|
+
|
71
|
+
def inner() -> msh.Unmarshaler:
|
72
|
+
dc_rfl = dc.reflect(rty)
|
73
|
+
v_rty = check.single(dc_rfl.fields_inspection.generic_replaced_field_annotations.values())
|
74
|
+
v_u = ctx.make_unmarshaler(v_rty)
|
75
|
+
return msh.WrappedUnmarshaler(lambda _, v: rty(v), v_u)
|
76
|
+
|
77
|
+
return inner
|
78
|
+
|
79
|
+
@msh.UnmarshalerFactoryMethodClass.make_unmarshaler.register
|
80
|
+
def _make_abstract(self, ctx: msh.UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], msh.Unmarshaler] | None: # noqa
|
81
|
+
if not (
|
82
|
+
isinstance(rty, type) and
|
83
|
+
issubclass(rty, TypedValue) and
|
84
|
+
lang.is_abstract_class(rty)
|
85
|
+
):
|
86
|
+
return None
|
87
|
+
|
88
|
+
return lambda: msh.make_polymorphism_unmarshaler(
|
71
89
|
_build_typed_value_poly(rty).impls,
|
72
90
|
msh.WrapperTypeTagging(),
|
73
91
|
ctx,
|
@@ -99,7 +117,7 @@ def _build_typed_values_impls(rty: rfl.Type) -> msh.Impls:
|
|
99
117
|
#
|
100
118
|
|
101
119
|
|
102
|
-
def build_typed_values_marshaler(ctx: msh.
|
120
|
+
def build_typed_values_marshaler(ctx: msh.MarshalFactoryContext, rty: rfl.Type) -> msh.Marshaler:
|
103
121
|
tv_m = msh.make_polymorphism_marshaler(
|
104
122
|
msh.Impls(_build_typed_values_impls(rty)),
|
105
123
|
msh.WrapperTypeTagging(),
|
@@ -108,20 +126,24 @@ def build_typed_values_marshaler(ctx: msh.MarshalContext, rty: rfl.Type) -> msh.
|
|
108
126
|
return msh.IterableMarshaler(tv_m)
|
109
127
|
|
110
128
|
|
111
|
-
class TypedValuesMarshalerFactory(msh.
|
112
|
-
@
|
113
|
-
def
|
114
|
-
|
129
|
+
class TypedValuesMarshalerFactory(msh.MarshalerFactoryMethodClass):
|
130
|
+
@msh.MarshalerFactoryMethodClass.make_marshaler.register
|
131
|
+
def _make_generic(self, ctx: msh.MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], msh.Marshaler] | None:
|
132
|
+
if not (isinstance(rty, rfl.Generic) and rty.cls is TypedValues):
|
133
|
+
return None
|
134
|
+
return lambda: build_typed_values_marshaler(ctx, rty)
|
115
135
|
|
116
|
-
@
|
117
|
-
def
|
118
|
-
|
136
|
+
@msh.MarshalerFactoryMethodClass.make_marshaler.register
|
137
|
+
def _make_concrete(self, ctx: msh.MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], msh.Marshaler] | None:
|
138
|
+
if rty is not TypedValues:
|
139
|
+
return None
|
140
|
+
return lambda: lang.raise_(NotImplementedError)
|
119
141
|
|
120
142
|
|
121
143
|
#
|
122
144
|
|
123
145
|
|
124
|
-
def build_typed_values_unmarshaler(ctx: msh.
|
146
|
+
def build_typed_values_unmarshaler(ctx: msh.UnmarshalFactoryContext, rty: rfl.Type) -> msh.Unmarshaler:
|
125
147
|
tv_u = msh.make_polymorphism_unmarshaler(
|
126
148
|
msh.Impls(_build_typed_values_impls(rty)),
|
127
149
|
msh.WrapperTypeTagging(),
|
@@ -130,14 +152,18 @@ def build_typed_values_unmarshaler(ctx: msh.UnmarshalContext, rty: rfl.Type) ->
|
|
130
152
|
return msh.IterableUnmarshaler(lambda it: TypedValues(*it), tv_u) # noqa
|
131
153
|
|
132
154
|
|
133
|
-
class TypedValuesUnmarshalerFactory(msh.
|
134
|
-
@
|
135
|
-
def _build(self, ctx: msh.
|
136
|
-
|
155
|
+
class TypedValuesUnmarshalerFactory(msh.UnmarshalerFactoryMethodClass):
|
156
|
+
@msh.UnmarshalerFactoryMethodClass.make_unmarshaler.register
|
157
|
+
def _build(self, ctx: msh.UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], msh.Unmarshaler] | None:
|
158
|
+
if not (isinstance(rty, rfl.Generic) and rty.cls is TypedValues):
|
159
|
+
return None
|
160
|
+
return lambda: build_typed_values_unmarshaler(ctx, rty)
|
137
161
|
|
138
|
-
@
|
139
|
-
def _build_concrete(self, ctx: msh.
|
140
|
-
|
162
|
+
@msh.UnmarshalerFactoryMethodClass.make_unmarshaler.register
|
163
|
+
def _build_concrete(self, ctx: msh.UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], msh.Unmarshaler] | None: # noqa
|
164
|
+
if rty is not TypedValues:
|
165
|
+
return None
|
166
|
+
return lambda: lang.raise_(NotImplementedError)
|
141
167
|
|
142
168
|
|
143
169
|
##
|
@@ -1,5 +1,5 @@
|
|
1
1
|
omlish/.omlish-manifests.json,sha256=FLw7xkPiSXuImZgqSP8BwrEib2R1doSzUPLUkc-QUIA,8410
|
2
|
-
omlish/__about__.py,sha256=
|
2
|
+
omlish/__about__.py,sha256=wqpHLPUSVDC5K6I55LXDB8pGFgSMoTsN383tFd6mTHc,3613
|
3
3
|
omlish/__init__.py,sha256=SsyiITTuK0v74XpKV8dqNaCmjOlan1JZKrHQv5rWKPA,253
|
4
4
|
omlish/c3.py,sha256=ZNIMl1kwg3qdei4DiUrJPQe5M81S1e76N-GuNSwLBAE,8683
|
5
5
|
omlish/cached.py,sha256=MLap_p0rdGoDIMVhXVHm1tsbcWobJF0OanoodV03Ju8,542
|
@@ -71,7 +71,7 @@ omlish/collections/bimap.py,sha256=3szDCscPJlFRtkpyVQNWneg4s50mr6Rd0jdTzVEIcnE,1
|
|
71
71
|
omlish/collections/coerce.py,sha256=tAls15v_7p5bUN33R7Zbko87KW5toWHl9fRialCqyNY,7030
|
72
72
|
omlish/collections/frozen.py,sha256=drarjcMFpwKhBM01b1Gh6XDcaRaUgpyuxEiqppaKRkU,4220
|
73
73
|
omlish/collections/hasheq.py,sha256=uHypfZlHhicQPvx9OOlpT9MSLwfc_mFil-WaxF9dTOo,3732
|
74
|
-
omlish/collections/identity.py,sha256=
|
74
|
+
omlish/collections/identity.py,sha256=Z6yfUg4PnqxWlMUzcy3MSGL7vckkzuMDBaujffQXjMw,4885
|
75
75
|
omlish/collections/mappings.py,sha256=c3ojUN9Ca3oGfmMXSFkDQYou5J15obDfgjCvzq3Url4,3833
|
76
76
|
omlish/collections/multimaps.py,sha256=azuif-PeLGvLpCE9_XX5zYx7XtVbsulWq0owvEKNy_g,3897
|
77
77
|
omlish/collections/ordered.py,sha256=jBSj5CamdKJAezXM8GlRd7jjaRDk6BHIeOhlxcC9lJI,2468
|
@@ -126,7 +126,7 @@ omlish/daemons/services.py,sha256=laoUeJU7eVHuWl1062FBjPSD7jchOjhpYDc5FT2B3dM,34
|
|
126
126
|
omlish/daemons/spawning.py,sha256=CsNhWDebyin_CYwWvLWNpY0djF010HjQTHATvw6dk-M,5349
|
127
127
|
omlish/daemons/targets.py,sha256=9nacraBQYPTnTvPwR4B_tdalF4nwFAXZeo4FSVcHoMg,3057
|
128
128
|
omlish/daemons/waiting.py,sha256=fuR51IHdBDRVtfdewcw_0qw8itoXqmtdR_qtkoBChuE,1702
|
129
|
-
omlish/dataclasses/__init__.py,sha256=
|
129
|
+
omlish/dataclasses/__init__.py,sha256=o4FsoqpLkVN55CPrANwpufRgfASxIFPACCpEOYWICpo,3677
|
130
130
|
omlish/dataclasses/_internals.py,sha256=_THiziiIslUyYC98Y_tZd5aZgvEF3FAGkDSwzRfcDuo,3247
|
131
131
|
omlish/dataclasses/debug.py,sha256=giBiv6aXvX0IagwNCW64qBzNjfOFr3-VmgDy_KYlb-k,29
|
132
132
|
omlish/dataclasses/errors.py,sha256=QeJVRmrZQer3m66jSDiuAyfAngCBtocMxfnsoSxzOVw,2520
|
@@ -288,8 +288,7 @@ omlish/formats/toml/writer.py,sha256=9NT8sRy3I9KubxFx56Qbislvrdtbd23rEuBT-GSdUYA
|
|
288
288
|
omlish/funcs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
289
289
|
omlish/funcs/builders.py,sha256=ZSBQS2xqriXp5x0t074EEZvuTmMp4Yue2YGBoTLAioo,4044
|
290
290
|
omlish/funcs/genmachine.py,sha256=BOxO1OTjxZ7ewv_WpqYkY8bwlGQIJIjwjvYMflEFa_M,2571
|
291
|
-
omlish/funcs/guard.py,sha256=
|
292
|
-
omlish/funcs/match.py,sha256=cBtG7kdpWdxvHwlte5CWlBxXSoJSV48joV4bwJJC3pk,6352
|
291
|
+
omlish/funcs/guard.py,sha256=OfxDQRJfnRmVrXOPK2QuUtJ3MN3dxMA_q0gIb7C8m2s,5958
|
293
292
|
omlish/funcs/pairs.py,sha256=XhYTJdqooAJKeoGZmEaiKYeFRq5-Dj2_y92IdBl_C20,4371
|
294
293
|
omlish/funcs/pipes.py,sha256=E1dQZMBmgT2qautG1vEqy5v3QBsO2Nzryv33j4YAngA,2520
|
295
294
|
omlish/graphs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -411,7 +410,7 @@ omlish/iterators/recipes.py,sha256=wOwOZg-zWG9Zc3wcAxJFSe2rtavVBYwZOfG09qYEx_4,4
|
|
411
410
|
omlish/iterators/tools.py,sha256=M16LXrJhMdsz5ea2qH0vws30ZvhQuQSCVFSLpRf_gTg,2096
|
412
411
|
omlish/iterators/transforms.py,sha256=YHVdD9nBkS1k4kogi4Ba0UOTU_pKkuX9jGw1Tqj3UMw,3598
|
413
412
|
omlish/iterators/unique.py,sha256=BSE-eanva8byFCJi09Nt2zzTsVr8LnTqY1PIInGYRs0,1396
|
414
|
-
omlish/lang/__init__.py,sha256=
|
413
|
+
omlish/lang/__init__.py,sha256=FiAlQCNPHoJABATaW-eFLEe8h0crfDgt--VFhKDTIJ0,10720
|
415
414
|
omlish/lang/asyncs.py,sha256=iIHJp7nvgJVj7zS0Ji7NsVSzz54vkzrj0Snc83dxe9g,1965
|
416
415
|
omlish/lang/attrstorage.py,sha256=UUnoENCMQF3twBfxBcIKa5mpXsAxWnNYDayhU8xgmpU,5224
|
417
416
|
omlish/lang/casing.py,sha256=3_c7cxQOc4z_YezaU2B4NCTAsPh_kDL4wUTK5kZU6kg,4675
|
@@ -423,9 +422,9 @@ omlish/lang/datetimes.py,sha256=01tg21QOx-PWDlm-CSFTalym3vpqF0EKzeinmtcVNoU,379
|
|
423
422
|
omlish/lang/descriptors.py,sha256=sVJ1Pr4ihp26Tu9UCvDSyfSf-DhBnFGnbpYIFF32c7g,6877
|
424
423
|
omlish/lang/enums.py,sha256=F9tflHfaAoV2MpyuhZzpfX9-H55M3zNa9hCszsngEo8,111
|
425
424
|
omlish/lang/errors.py,sha256=shcS-NCnEUudF8qC_SmO2TQyjivKlS4TDjaz_faqQ0c,44
|
426
|
-
omlish/lang/functions.py,sha256=
|
425
|
+
omlish/lang/functions.py,sha256=tZL7Yi5Oy34lvzP6HhWmV5q1eg5-mk3FrWEjsmhKRhY,5707
|
427
426
|
omlish/lang/generators.py,sha256=nJiSmDpsfPiypGzJ8qlOO7-BUnCsrAeDow9mhtGgBio,5196
|
428
|
-
omlish/lang/iterables.py,sha256=
|
427
|
+
omlish/lang/iterables.py,sha256=5CJNkLyY4Oq43UkiM7KCgV9F6jzrlr9SLiuNx3DAvm8,3608
|
429
428
|
omlish/lang/lazyglobals.py,sha256=YfPtWgNEa0ULtbIiQIQ12pbafUwd6INQRw_PFcAabjo,2282
|
430
429
|
omlish/lang/maybes.py,sha256=8GUpqJvyx9y5PQBQBBx6yTSE5WKsMbXMHPt4_vojKUw,209
|
431
430
|
omlish/lang/maysync.py,sha256=S2Q_rGC4AxRa1UsGJdSzZsYpgOcX9Y8ZmYGA9v8OWn8,1635
|
@@ -470,12 +469,12 @@ omlish/lite/__init__.py,sha256=cyZEpGob7XjU8DohyNxVe5CQRk4CQ5vrHL42OdhQb8w,148
|
|
470
469
|
omlish/lite/abstract.py,sha256=Z3kLviPNGLkmA8m8BZILzWxez_sP18OyzgMP3-c2-RI,4068
|
471
470
|
omlish/lite/args.py,sha256=ILJXAiN3KjIoJwY42aKpYPngUdxHIy9ssVIExFVz3fE,978
|
472
471
|
omlish/lite/asyncs.py,sha256=ITnHvg1gq4Wl6PmhwK6DTKriNLBfxFfiVLE9QL6LEHk,3254
|
473
|
-
omlish/lite/attrops.py,sha256=
|
472
|
+
omlish/lite/attrops.py,sha256=02DNBjOl27NjznkwolgPwtWpA1q3UPUuwOjHsgG4oLo,11381
|
474
473
|
omlish/lite/cached.py,sha256=AF0PdB2k4h2dyNc5tzrmnNrb9zKnoMPQU3WA8KrhS_o,3108
|
475
474
|
omlish/lite/check.py,sha256=ytCkwZoKfOlJqylL-AGm8C2WfsWJd2q3kFbnZCzX3_M,13844
|
476
475
|
omlish/lite/configs.py,sha256=4-1uVxo-aNV7vMKa7PVNhM610eejG1WepB42-Dw2xQI,914
|
477
476
|
omlish/lite/contextmanagers.py,sha256=usDzBoNqJi98AccVlwgZoMvoBXOe9wyx2MreZtWhJy4,5863
|
478
|
-
omlish/lite/dataclasses.py,sha256=
|
477
|
+
omlish/lite/dataclasses.py,sha256=sBsClTxr5nmoahgXzruyZS6GqEWYGmDs8YvAXOIMl74,4814
|
479
478
|
omlish/lite/imports.py,sha256=GyEDKL-WuHtdOKIL-cc8aFd0-bHwZFDEjAB52ItabX0,1341
|
480
479
|
omlish/lite/inject.py,sha256=BQgjBj2mzJgMimLam-loSpQzcb31-8NYPVRQgHVv3cQ,29159
|
481
480
|
omlish/lite/json.py,sha256=m0Ce9eqUZG23-H7-oOp8n1sf4fzno5vtK4AK_4Vc-Mg,706
|
@@ -528,64 +527,65 @@ omlish/manifests/globals.py,sha256=kVqQ-fT4kc7xWzLHoI731GviitFPv2v2yqw-p7t7Exs,2
|
|
528
527
|
omlish/manifests/loading.py,sha256=s6KnhdFQCsI2i0Rus1sMU0so2v8dUBnk59BJkSnxGt8,17514
|
529
528
|
omlish/manifests/static.py,sha256=9BaPBLkuzxHmg5A-5k9BjjBFINCdmFOIu06dMFgCfz4,497
|
530
529
|
omlish/manifests/types.py,sha256=NeOGuIVrcbqjCDbQ3MnCxxHAgHnw0CkWJsBzo230PWE,453
|
531
|
-
omlish/marshal/__init__.py,sha256=
|
530
|
+
omlish/marshal/__init__.py,sha256=RC4AnLMHRFF51-Be1W9Lefcv1g9L89tM7UiPM2tP1Xg,6530
|
532
531
|
omlish/marshal/globals.py,sha256=Q6G18hcUwUDDNnpyRPnR5Tn_XZpZCSIEXo09nYSOaNU,2236
|
533
532
|
omlish/marshal/naming.py,sha256=Mk5YrbES836_KflNNRoc5Ajd96iMYLQIMERKx1KpT4g,865
|
534
|
-
omlish/marshal/standard.py,sha256=
|
533
|
+
omlish/marshal/standard.py,sha256=8Qy5L3qMHO-V_fu78tM62wMcGpF0kgrFrxn06IRbFXQ,6906
|
535
534
|
omlish/marshal/base/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
536
535
|
omlish/marshal/base/configs.py,sha256=y_JRghQgu8mJjPspSZcJQLhjevEuJE2kyxCdu3wGKvo,271
|
537
|
-
omlish/marshal/base/contexts.py,sha256=
|
536
|
+
omlish/marshal/base/contexts.py,sha256=5dsfjEgKn9Nt-yuzG8ZyJUc6kIQfXHuGoWGo5efIqf4,2683
|
538
537
|
omlish/marshal/base/errors.py,sha256=jmN3vl_U_hB6L0wAvuO7ORG27vXF7KEUk-1TxxK2mYA,308
|
539
|
-
omlish/marshal/base/funcs.py,sha256=
|
540
|
-
omlish/marshal/base/options.py,sha256=
|
538
|
+
omlish/marshal/base/funcs.py,sha256=UIlVHZ_vARJ8MNKsR6n5x5GnFQQ7Z0MaIZKYxHMsZaQ,1470
|
539
|
+
omlish/marshal/base/options.py,sha256=Yuk4VDeKw9N26wSHda9_mMWj1hdgQTnenJ6hPYfrFts,235
|
541
540
|
omlish/marshal/base/overrides.py,sha256=543hP4_y2JRThUOamCE0dPfgucbepVV8e_YF-_PJk6U,993
|
542
541
|
omlish/marshal/base/registries.py,sha256=NRH5X4nE_aF7vcTi4_5qqQpYbYru2Ud6aD0eKfuJ_Ws,5903
|
543
|
-
omlish/marshal/base/types.py,sha256=
|
542
|
+
omlish/marshal/base/types.py,sha256=DtyY7W-kzU0oXtQytrBKDIPzfWnh2OJW7oMHSNB-TrA,3593
|
544
543
|
omlish/marshal/base/values.py,sha256=QF6OateG5kjRPHYza08wscThhg20oryf-aVQrxjfkC0,212
|
545
544
|
omlish/marshal/composite/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
546
|
-
omlish/marshal/composite/iterables.py,sha256=
|
547
|
-
omlish/marshal/composite/literals.py,sha256=
|
548
|
-
omlish/marshal/composite/mappings.py,sha256=
|
549
|
-
omlish/marshal/composite/maybes.py,sha256=
|
550
|
-
omlish/marshal/composite/newtypes.py,sha256=
|
551
|
-
omlish/marshal/composite/optionals.py,sha256=
|
552
|
-
omlish/marshal/composite/special.py,sha256=
|
553
|
-
omlish/marshal/composite/unions.py,sha256=qUVAbUS16YI1toRmq0liyuMUQSq1d2Ox5mAW0zYCdog,6058
|
545
|
+
omlish/marshal/composite/iterables.py,sha256=zswx4nmYPWNu1Ht7myjNwy_q5a4Sq-hH7Ky7rIYBqv4,3148
|
546
|
+
omlish/marshal/composite/literals.py,sha256=KrrvPuzGZGhlcY64Nt1_kNrCRWu671JIdTkIaNQGOPk,1854
|
547
|
+
omlish/marshal/composite/mappings.py,sha256=W2RKCa-7JEOvimiCR23sexV84hlFh7j5aNVQ4p9uMeQ,3319
|
548
|
+
omlish/marshal/composite/maybes.py,sha256=JCT1ZDd-x__Y2EM8BmNANVIC2k2eNxTN2MtPf7O-K0g,2705
|
549
|
+
omlish/marshal/composite/newtypes.py,sha256=t0YL76AIYk9jCwz6g6oZburVm2mZ0_m89XTfX1T022k,973
|
550
|
+
omlish/marshal/composite/optionals.py,sha256=MfHJ6w43OzWJKcO94JOZX1b6HTCvexys5BEEoYtJrGg,1708
|
551
|
+
omlish/marshal/composite/special.py,sha256=34I0IsUrZjtTrk0qgPAcvyT-lkHNCkvAIkjgl6ulYhw,1364
|
554
552
|
omlish/marshal/composite/wrapped.py,sha256=xC8k21wJOpSkpAn7794hBTPBRw-HPC9sOF3WRlUh_BA,785
|
553
|
+
omlish/marshal/composite/unions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
554
|
+
omlish/marshal/composite/unions/literals.py,sha256=__8oTce5sNbM-fDfQ8UhllQOdzu4fmvEIkYWcS6qr2U,2810
|
555
|
+
omlish/marshal/composite/unions/primitives.py,sha256=xP38hnQXkF0t2xaKyHilhqpAeLwCMl9K6a6ekI_VtW0,2961
|
555
556
|
omlish/marshal/factories/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
556
|
-
omlish/marshal/factories/invalidate.py,sha256=
|
557
|
-
omlish/marshal/factories/
|
558
|
-
omlish/marshal/factories/multi.py,sha256=
|
559
|
-
omlish/marshal/factories/recursive.py,sha256=
|
560
|
-
omlish/marshal/factories/
|
561
|
-
omlish/marshal/factories/
|
562
|
-
omlish/marshal/factories/typemap.py,sha256=CxScQbRw3VwILGhf38v2yOiof45YJ9p2LQhZ37SHNj8,1606
|
557
|
+
omlish/marshal/factories/invalidate.py,sha256=qoI5BI6tsTmrZc1ahz5c_YjMpHKzlc0Fo-n9lCJbUeQ,1987
|
558
|
+
omlish/marshal/factories/method.py,sha256=Uk92_AGnEdH5P4CrebuFWPhONDk4ydteW7hSRfI6ZtI,884
|
559
|
+
omlish/marshal/factories/multi.py,sha256=IbsUbzPiIho55CzZtPQk2ub9eAdvwoFy2Q8XliBaK5o,1279
|
560
|
+
omlish/marshal/factories/recursive.py,sha256=spoPD0w7kyq3tiXFxlNSh2SYCFrPNzM6zPm3234sEHI,2984
|
561
|
+
omlish/marshal/factories/typecache.py,sha256=8DwgyAKEA7scdhSxndPbC3NltkFViM_C4nP8xViSUKc,1598
|
562
|
+
omlish/marshal/factories/typemap.py,sha256=-Dl3Z-MvssSP_oPj3i32_72A9nSHNM1HtpTuys7tDHg,1995
|
563
563
|
omlish/marshal/factories/moduleimport/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
564
564
|
omlish/marshal/factories/moduleimport/configs.py,sha256=8g6FSPmyo0IOYSWYp5kqfJACZxL9SvzlHzrSzucNZyg,538
|
565
|
-
omlish/marshal/factories/moduleimport/factories.py,sha256=
|
565
|
+
omlish/marshal/factories/moduleimport/factories.py,sha256=MEyTruCxPvcLvIZs0Wwa-5_8wW59Nc-Mv8U1XI8GAAc,2404
|
566
566
|
omlish/marshal/objects/__init__.py,sha256=F4wej8L_tedC8ETYxAnmKfdPR9TjsqIus9Z3nZofYuc,182
|
567
|
-
omlish/marshal/objects/dataclasses.py,sha256=
|
567
|
+
omlish/marshal/objects/dataclasses.py,sha256=wQ6s7z6zuoPJfUN4TqQSeDjxj0MzUJyH4vwYORnrxUY,10431
|
568
568
|
omlish/marshal/objects/helpers.py,sha256=hj5I1pILt3QFSVkYJNrSO3wiCaalAopEYWPL17Ip4zs,1102
|
569
|
-
omlish/marshal/objects/marshal.py,sha256=
|
569
|
+
omlish/marshal/objects/marshal.py,sha256=KhS2ZTW1X5N-mK1qYlb-qIpEqU5ZEp8TLTXLhttEoMU,2818
|
570
570
|
omlish/marshal/objects/metadata.py,sha256=maGqyQl0GE9xWK17DQjXxhZWRh3nRwH4fgklrA8XVQI,3392
|
571
|
-
omlish/marshal/objects/namedtuples.py,sha256=
|
572
|
-
omlish/marshal/objects/unmarshal.py,sha256=
|
571
|
+
omlish/marshal/objects/namedtuples.py,sha256=YohP58NraqI9SZzMtLk6s0CrWVow417fxjA2Aqq-7vA,3168
|
572
|
+
omlish/marshal/objects/unmarshal.py,sha256=91wxKiMsPaJHYYUfImGkEcsg4cycIEw8_xGsZ6QrrZQ,3812
|
573
573
|
omlish/marshal/polymorphism/__init__.py,sha256=e2UTrSL0qp7w_1vkdxDWd7sXlWhep2KPV49-BB64ma8,130
|
574
|
-
omlish/marshal/polymorphism/marshal.py,sha256=
|
574
|
+
omlish/marshal/polymorphism/marshal.py,sha256=Xsos29MvL7umwgO3ReNu7KMPYGyJ-qrgFIUJGYdmT70,2295
|
575
575
|
omlish/marshal/polymorphism/metadata.py,sha256=s5lNTzvP487niVorDUy6RFeTB7hde89ENgm-7I_MQg0,3622
|
576
576
|
omlish/marshal/polymorphism/standard.py,sha256=sfxKVjFG8tUam_U75_rFMY2-JSWw_l1_HBg2MrXjQHE,1096
|
577
|
-
omlish/marshal/polymorphism/unions.py,sha256=
|
578
|
-
omlish/marshal/polymorphism/unmarshal.py,sha256=
|
577
|
+
omlish/marshal/polymorphism/unions.py,sha256=JyXhQOV9bHbCfuHq94QU8TnHROS_eRbXycfwBvG0mzw,2141
|
578
|
+
omlish/marshal/polymorphism/unmarshal.py,sha256=v_bZe6jDH5Y04csfQe76hDTY25H-kEzTSzQZjhjsZrQ,2512
|
579
579
|
omlish/marshal/singular/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
580
580
|
omlish/marshal/singular/base64.py,sha256=OZ3Ydwy64S0M-xlktYy5MagzyzTOVYayUXblq8ZK-AE,1164
|
581
581
|
omlish/marshal/singular/datetimes.py,sha256=nzOf8LRwAB08X80N_NmWuE3rOrYG80ZgIaZO3549WnE,3784
|
582
|
-
omlish/marshal/singular/enums.py,sha256=
|
582
|
+
omlish/marshal/singular/enums.py,sha256=RzP9R9NhPfo-Yq-yF-Awg-_dnnJoqAeAlIYGZoDKz4A,1493
|
583
583
|
omlish/marshal/singular/numbers.py,sha256=32_lSiaQc796u0WsPyiYORiJoaI5qh2IZxiIfF8n360,1746
|
584
584
|
omlish/marshal/singular/primitives.py,sha256=T1mRNMin7OOBjsBkAh1xVbHa-VBmtMfL55mhCfiruIg,1360
|
585
585
|
omlish/marshal/singular/uuids.py,sha256=J6Swxzm0rFvAMCmErJb4WpSPmnQyts7qOqy43Y1BugI,984
|
586
586
|
omlish/marshal/trivial/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
587
|
-
omlish/marshal/trivial/any.py,sha256=
|
588
|
-
omlish/marshal/trivial/forbidden.py,sha256=
|
587
|
+
omlish/marshal/trivial/any.py,sha256=9SmivhlphEn8kdUNsu7qRhQITrcHfkT6JmipAtMzb1k,886
|
588
|
+
omlish/marshal/trivial/forbidden.py,sha256=_-tSgy2UpDKHERsRm8Alg1FvU7vg4YrwvKB-JI2CrRg,1222
|
589
589
|
omlish/marshal/trivial/nop.py,sha256=PDXT0B9RR-ghG6ExuK9BH2J-nHEnoTYGNdVaNAyRzSk,506
|
590
590
|
omlish/math/__init__.py,sha256=bcdEEM3l4YNPJvTY_gD-7ARa5HEBNFTfvkVDTTzaNOQ,1531
|
591
591
|
omlish/math/bits.py,sha256=pcTuWxNXXfG-CtTITNNbW3YConAkCeU8PLNcglCc43E,533
|
@@ -604,7 +604,7 @@ omlish/os/environ.py,sha256=fDjnSO2Qz6lpvICx54JZpdPF-BxL4zKAWU3x_6UTxCI,3681
|
|
604
604
|
omlish/os/fcntl.py,sha256=EUa4TkeqdKix-uIweRitIZsgT9ohY7OQ5QiIhUW9S0c,1512
|
605
605
|
omlish/os/filemodes.py,sha256=JjHXZ7_BUQRphlA6_DkQoRSOEXxQUWWoKiS2-54rMVo,4586
|
606
606
|
omlish/os/files.py,sha256=PmFQIesLmpYORm4dMKTkj2PeS8iu-KbfPmjZHaabeVc,1117
|
607
|
-
omlish/os/forkhooks.py,sha256=
|
607
|
+
omlish/os/forkhooks.py,sha256=T9BALcFeffR3xJbekSuYUvftwiXiwnO7N8dvtbmo98I,5761
|
608
608
|
omlish/os/journald.py,sha256=RS6Vjlm1N-J7I6h39A5onmKueCA4ViRhrlDam2523V0,3921
|
609
609
|
omlish/os/linux.py,sha256=CfnYR1vJooo74OfeiSB6EaB1KN5SLz9x3b1KXtJIRQ4,18949
|
610
610
|
omlish/os/mangle.py,sha256=1Z_gYNiRiHn7wAA8tGEumra3lD4r9Isn581Ml2auJZI,531
|
@@ -663,7 +663,7 @@ omlish/specs/jmespath/parser.py,sha256=uNk9_xQ9cZJC1h5naoH1HMbCs4B0WhV2jN5AvhdKT
|
|
663
663
|
omlish/specs/jmespath/scope.py,sha256=gsVjmAVF0b7s2SevWb0rBbURayiMSIuXfzO4v1ONIrY,1595
|
664
664
|
omlish/specs/jmespath/visitor.py,sha256=6OCi7oa4IsGW5fCqAeFuXYEwn-aLKuMrNMFtQKSpJWo,16951
|
665
665
|
omlish/specs/jsonrpc/__init__.py,sha256=u2kcJeo6YWEvFYf7OqDNKThszGLSmXYFNJpqXmXgm1M,504
|
666
|
-
omlish/specs/jsonrpc/_marshal.py,sha256=
|
666
|
+
omlish/specs/jsonrpc/_marshal.py,sha256=RQZC1KEmI4tbPieRZ2rAcn0QDN_a6mhSVirdB57XewA,2102
|
667
667
|
omlish/specs/jsonrpc/conns.py,sha256=zvWnBHuSoGnvbGVk72Usp4IFsLscrzPozqR2hmFjnDI,7029
|
668
668
|
omlish/specs/jsonrpc/errors.py,sha256=WxEU7k1TqeZAo_H6eU0LcrXSd-Gi_3fTvtxjXZ9qKww,712
|
669
669
|
omlish/specs/jsonrpc/types.py,sha256=Se9ecG-_k-kY_Qlt9QD2t3y26oY4sXTcskp6XZfVans,3054
|
@@ -693,7 +693,7 @@ omlish/specs/jsonschema/schemas/draft202012/vocabularies/meta-data.json,sha256=j
|
|
693
693
|
omlish/specs/jsonschema/schemas/draft202012/vocabularies/unevaluated.json,sha256=Lb-8tzmUtnCwl2SSre4f_7RsIWgnhNL1pMpWH54tDLQ,506
|
694
694
|
omlish/specs/jsonschema/schemas/draft202012/vocabularies/validation.json,sha256=cBCjHlQfMtK-ch4t40jfdcmzaHaj7TBId_wKvaHTelg,2834
|
695
695
|
omlish/specs/openapi/__init__.py,sha256=KS7OHPBlXwBeTvmsUQy0VMzKYdz2RyH3qLF3bU0NXUw,147
|
696
|
-
omlish/specs/openapi/_marshal.py,sha256=
|
696
|
+
omlish/specs/openapi/_marshal.py,sha256=DpI0ibKPIpOA1AsxrCawPHaJfPmGmexnqUjtLb64UbI,4712
|
697
697
|
omlish/specs/openapi/openapi.py,sha256=6KGY_d8HOyG7ssHIWM40MCXgIMzNLiLKHYNggTSpAYM,12027
|
698
698
|
omlish/sql/__init__.py,sha256=JjgIiP2YfiHHIANP7qgkJUG0IMIRzzvKntyhdDKeNdY,384
|
699
699
|
omlish/sql/abc.py,sha256=3hrCjB4jnPVMef_YXClCblzYUZ9l9yaxJJdd5_Nu9GM,4043
|
@@ -821,13 +821,13 @@ omlish/typedvalues/collection.py,sha256=CK4Vk9kJqAt2V8o6I4zGyv2u9DKov12uSvsGdqEd
|
|
821
821
|
omlish/typedvalues/consumer.py,sha256=lDOE-O_sgGbOvbcBg2g5ZRaV2WixnuEYxFsJBaj18oU,4690
|
822
822
|
omlish/typedvalues/generic.py,sha256=ft-x4X3k1oFirtYnDfsvrI3ZQikWM8lGLrvrOEbcGq0,742
|
823
823
|
omlish/typedvalues/holder.py,sha256=vu-umn-h1nvUqmtV5T9ZfQ_OoOYsERu8PhI2N48Ryns,1133
|
824
|
-
omlish/typedvalues/marshal.py,sha256=
|
824
|
+
omlish/typedvalues/marshal.py,sha256=2xqX6JllhtGpmeYkU7C-qzgU__0x-vd6CzYbAsocQlc,6058
|
825
825
|
omlish/typedvalues/of_.py,sha256=UXkxSj504WI2UrFlqdZJbu2hyDwBhL7XVrc2qdR02GQ,1309
|
826
826
|
omlish/typedvalues/reflect.py,sha256=PAvKW6T4cW7u--iX80w3HWwZUS3SmIZ2_lQjT65uAyk,1026
|
827
827
|
omlish/typedvalues/values.py,sha256=ym46I-q2QJ_6l4UlERqv3yj87R-kp8nCKMRph0xQ3UA,1307
|
828
|
-
omlish-0.0.0.
|
829
|
-
omlish-0.0.0.
|
830
|
-
omlish-0.0.0.
|
831
|
-
omlish-0.0.0.
|
832
|
-
omlish-0.0.0.
|
833
|
-
omlish-0.0.0.
|
828
|
+
omlish-0.0.0.dev455.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
|
829
|
+
omlish-0.0.0.dev455.dist-info/METADATA,sha256=qPrVr-lvAsmMg6yb-y5H9a4wRc4ZzwGYiKUznIHqMIY,19003
|
830
|
+
omlish-0.0.0.dev455.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
831
|
+
omlish-0.0.0.dev455.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
|
832
|
+
omlish-0.0.0.dev455.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
|
833
|
+
omlish-0.0.0.dev455.dist-info/RECORD,,
|
omlish/funcs/match.py
DELETED
@@ -1,229 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Analogous to scala's partial functions ( https://www.scala-lang.org/api/current/scala/PartialFunction.html ).
|
3
|
-
|
4
|
-
TODO:
|
5
|
-
- unify MatchFnClass with dispatch.method?
|
6
|
-
- __call__ = mfs.method(); @__call__.register(lambda: ...) def _call_... ?
|
7
|
-
- not really the same thing, dispatch is unordered this is necessarily ordered
|
8
|
-
- !! well.. unify interface at least?
|
9
|
-
- guard(*a, **k) -> bool + fn(*a, **k) -> T becomes dispatch(*a, **k) -> (Callable -> T) | None
|
10
|
-
"""
|
11
|
-
import abc
|
12
|
-
import dataclasses as dc
|
13
|
-
import typing as ta
|
14
|
-
|
15
|
-
from .. import lang
|
16
|
-
|
17
|
-
|
18
|
-
T = ta.TypeVar('T')
|
19
|
-
P = ta.ParamSpec('P')
|
20
|
-
|
21
|
-
|
22
|
-
##
|
23
|
-
|
24
|
-
|
25
|
-
class MatchGuardError(Exception):
|
26
|
-
pass
|
27
|
-
|
28
|
-
|
29
|
-
class MatchFn(lang.Abstract, ta.Generic[P, T]):
|
30
|
-
@abc.abstractmethod
|
31
|
-
def guard(self, *args: P.args, **kwargs: P.kwargs) -> bool:
|
32
|
-
raise NotImplementedError
|
33
|
-
|
34
|
-
@abc.abstractmethod
|
35
|
-
def fn(self, *args: P.args, **kwargs: P.kwargs) -> T:
|
36
|
-
raise NotImplementedError
|
37
|
-
|
38
|
-
def __get__(self, instance, owner=None):
|
39
|
-
return self
|
40
|
-
|
41
|
-
@ta.final
|
42
|
-
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T:
|
43
|
-
if not self.guard(*args, **kwargs):
|
44
|
-
raise MatchGuardError(*args, **kwargs)
|
45
|
-
return self.fn(*args, **kwargs)
|
46
|
-
|
47
|
-
|
48
|
-
##
|
49
|
-
|
50
|
-
|
51
|
-
@dc.dataclass(frozen=True)
|
52
|
-
class SimpleMatchFn(MatchFn[P, T]):
|
53
|
-
_guard: ta.Callable[P, bool]
|
54
|
-
_fn: ta.Callable[P, T]
|
55
|
-
|
56
|
-
def guard(self, *args: P.args, **kwargs: P.kwargs) -> bool:
|
57
|
-
return self._guard(*args, **kwargs)
|
58
|
-
|
59
|
-
def fn(self, *args: P.args, **kwargs: P.kwargs) -> T:
|
60
|
-
return self._fn(*args, **kwargs)
|
61
|
-
|
62
|
-
def __get__(self, instance, owner=None):
|
63
|
-
return self.__class__(
|
64
|
-
self._guard.__get__(instance, owner), # noqa
|
65
|
-
self._fn.__get__(instance, owner), # noqa
|
66
|
-
)
|
67
|
-
|
68
|
-
|
69
|
-
@ta.overload
|
70
|
-
def simple(guard: ta.Callable[..., bool], fn: ta.Callable[P, T]) -> SimpleMatchFn[P, T]:
|
71
|
-
...
|
72
|
-
|
73
|
-
|
74
|
-
@ta.overload
|
75
|
-
def simple(guard: ta.Callable[..., bool]) -> ta.Callable[[ta.Callable[P, T]], SimpleMatchFn[P, T]]:
|
76
|
-
...
|
77
|
-
|
78
|
-
|
79
|
-
def simple(guard, fn=None):
|
80
|
-
def inner(fn): # noqa
|
81
|
-
return SimpleMatchFn(guard, fn)
|
82
|
-
if fn is not None:
|
83
|
-
return inner(fn)
|
84
|
-
else:
|
85
|
-
return inner
|
86
|
-
|
87
|
-
|
88
|
-
##
|
89
|
-
|
90
|
-
|
91
|
-
class AmbiguousMatchesError(Exception):
|
92
|
-
pass
|
93
|
-
|
94
|
-
|
95
|
-
@dc.dataclass(frozen=True)
|
96
|
-
class MultiMatchFn(MatchFn[P, T]):
|
97
|
-
children: ta.Sequence[MatchFn[P, T]]
|
98
|
-
strict: bool = False
|
99
|
-
|
100
|
-
def match(self, *args: P.args, **kwargs: P.kwargs) -> MatchFn[P, T] | None:
|
101
|
-
matches = []
|
102
|
-
for cur in self.children:
|
103
|
-
if cur.guard(*args, **kwargs):
|
104
|
-
if self.strict:
|
105
|
-
matches.append(cur)
|
106
|
-
else:
|
107
|
-
return cur
|
108
|
-
if not matches:
|
109
|
-
return None
|
110
|
-
elif len(matches) > 1:
|
111
|
-
raise AmbiguousMatchesError
|
112
|
-
else:
|
113
|
-
return matches[0]
|
114
|
-
|
115
|
-
def guard(self, *args: P.args, **kwargs: P.kwargs) -> bool:
|
116
|
-
return self.match(*args, **kwargs) is not None
|
117
|
-
|
118
|
-
def fn(self, *args: P.args, **kwargs: P.kwargs) -> T:
|
119
|
-
if (m := self.match(*args, **kwargs)) is None:
|
120
|
-
raise MatchGuardError(*args, **kwargs)
|
121
|
-
return m.fn(*args, **kwargs)
|
122
|
-
|
123
|
-
def __get__(self, instance, owner=None):
|
124
|
-
return self.__class__(
|
125
|
-
[c.__get__(instance, owner) for c in self.children],
|
126
|
-
strict=self.strict,
|
127
|
-
)
|
128
|
-
|
129
|
-
|
130
|
-
def multi(*children: MatchFn[P, T], strict: bool = False) -> MultiMatchFn: # MultiMatchFn[P[0], T[-1]]
|
131
|
-
return MultiMatchFn(children, strict=strict) # noqa
|
132
|
-
|
133
|
-
|
134
|
-
##
|
135
|
-
|
136
|
-
|
137
|
-
class CachedMatchFn(MatchFn[P, T]):
|
138
|
-
@staticmethod
|
139
|
-
def _default_key(*args, **kwargs):
|
140
|
-
return (args, tuple(sorted(kwargs.items(), key=lambda t: t[0])))
|
141
|
-
|
142
|
-
def __init__(
|
143
|
-
self,
|
144
|
-
f: MatchFn[P, T],
|
145
|
-
*,
|
146
|
-
key: ta.Callable[P, ta.Any] = _default_key,
|
147
|
-
lock: lang.DefaultLockable = None,
|
148
|
-
) -> None:
|
149
|
-
super().__init__()
|
150
|
-
|
151
|
-
self._f = f
|
152
|
-
self._key = key
|
153
|
-
self._lock = lock
|
154
|
-
self._lock_impl = lang.default_lock(lock)()
|
155
|
-
self._dct: dict[ta.Any, lang.Maybe[ta.Any]] = {}
|
156
|
-
|
157
|
-
def guard(self, *args: P.args, **kwargs: P.kwargs) -> bool:
|
158
|
-
with self._lock_impl:
|
159
|
-
k = self._key(*args, **kwargs)
|
160
|
-
try:
|
161
|
-
e = self._dct[k]
|
162
|
-
except KeyError:
|
163
|
-
if self._f.guard(*args, **kwargs):
|
164
|
-
return True
|
165
|
-
else:
|
166
|
-
self._dct[k] = lang.empty()
|
167
|
-
return False
|
168
|
-
else:
|
169
|
-
return e.present
|
170
|
-
|
171
|
-
def fn(self, *args: P.args, **kwargs: P.kwargs) -> T:
|
172
|
-
with self._lock_impl:
|
173
|
-
k = self._key(*args, **kwargs)
|
174
|
-
try:
|
175
|
-
e = self._dct[k]
|
176
|
-
except KeyError:
|
177
|
-
try:
|
178
|
-
ret = self._f(*args, **kwargs)
|
179
|
-
except MatchGuardError:
|
180
|
-
self._dct[k] = lang.empty()
|
181
|
-
raise
|
182
|
-
else:
|
183
|
-
self._dct[k] = lang.just(ret)
|
184
|
-
return ret
|
185
|
-
else:
|
186
|
-
if e.present:
|
187
|
-
return e.must()
|
188
|
-
else:
|
189
|
-
raise MatchGuardError(*args, **kwargs)
|
190
|
-
|
191
|
-
def __get__(self, instance, owner=None):
|
192
|
-
return self.__class__(self._f.__get__(instance, owner), key=self._key) # noqa
|
193
|
-
|
194
|
-
|
195
|
-
cached = CachedMatchFn
|
196
|
-
|
197
|
-
|
198
|
-
##
|
199
|
-
|
200
|
-
|
201
|
-
class MatchFnClass(MatchFn[P, T]):
|
202
|
-
_cls_match_fn: ta.ClassVar[MultiMatchFn]
|
203
|
-
|
204
|
-
__match_fn: MatchFn[P, T] | None = None
|
205
|
-
|
206
|
-
@property
|
207
|
-
def _match_fn(self) -> MatchFn[P, T]:
|
208
|
-
if (mf := self.__match_fn) is None:
|
209
|
-
mf = self.__match_fn = self._cls_match_fn.__get__(self)
|
210
|
-
return mf
|
211
|
-
|
212
|
-
def __init_subclass__(cls, strict: bool = False, **kwargs: ta.Any) -> None:
|
213
|
-
super().__init_subclass__(**kwargs)
|
214
|
-
|
215
|
-
if '_cls_match_fn' in cls.__dict__:
|
216
|
-
raise AttributeError('_cls_match_fn')
|
217
|
-
|
218
|
-
d = {}
|
219
|
-
for c in cls.__mro__:
|
220
|
-
for a, o in c.__dict__.items():
|
221
|
-
if isinstance(o, MatchFn) and a not in d:
|
222
|
-
d[a] = o
|
223
|
-
cls._cls_match_fn = MultiMatchFn(list(d.values()), strict=strict)
|
224
|
-
|
225
|
-
def guard(self, *args: P.args, **kwargs: P.kwargs) -> bool:
|
226
|
-
return self._match_fn.guard(*args, **kwargs)
|
227
|
-
|
228
|
-
def fn(self, *args: P.args, **kwargs: P.kwargs) -> T:
|
229
|
-
return self._match_fn.fn(*args, **kwargs)
|