omlish 0.0.0.dev453__py3-none-any.whl → 0.0.0.dev454__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.
Files changed (52) hide show
  1. omlish/__about__.py +2 -2
  2. omlish/collections/identity.py +1 -0
  3. omlish/dataclasses/__init__.py +2 -0
  4. omlish/funcs/guard.py +27 -16
  5. omlish/lang/__init__.py +1 -0
  6. omlish/lang/iterables.py +8 -0
  7. omlish/lite/attrops.py +2 -0
  8. omlish/lite/dataclasses.py +30 -0
  9. omlish/marshal/__init__.py +12 -11
  10. omlish/marshal/base/contexts.py +4 -7
  11. omlish/marshal/base/funcs.py +16 -11
  12. omlish/marshal/base/types.py +17 -7
  13. omlish/marshal/composite/iterables.py +31 -20
  14. omlish/marshal/composite/literals.py +14 -18
  15. omlish/marshal/composite/mappings.py +34 -23
  16. omlish/marshal/composite/maybes.py +27 -19
  17. omlish/marshal/composite/newtypes.py +14 -14
  18. omlish/marshal/composite/optionals.py +12 -14
  19. omlish/marshal/composite/special.py +13 -13
  20. omlish/marshal/composite/unions/__init__.py +0 -0
  21. omlish/marshal/composite/unions/literals.py +91 -0
  22. omlish/marshal/composite/unions/primitives.py +101 -0
  23. omlish/marshal/factories/invalidate.py +16 -66
  24. omlish/marshal/factories/method.py +28 -0
  25. omlish/marshal/factories/moduleimport/factories.py +13 -54
  26. omlish/marshal/factories/multi.py +11 -23
  27. omlish/marshal/factories/recursive.py +40 -56
  28. omlish/marshal/factories/typecache.py +23 -75
  29. omlish/marshal/factories/typemap.py +40 -41
  30. omlish/marshal/objects/dataclasses.py +106 -97
  31. omlish/marshal/objects/marshal.py +15 -12
  32. omlish/marshal/objects/namedtuples.py +46 -40
  33. omlish/marshal/objects/unmarshal.py +16 -13
  34. omlish/marshal/polymorphism/marshal.py +6 -9
  35. omlish/marshal/polymorphism/unions.py +15 -9
  36. omlish/marshal/polymorphism/unmarshal.py +6 -8
  37. omlish/marshal/singular/enums.py +12 -18
  38. omlish/marshal/standard.py +8 -8
  39. omlish/marshal/trivial/forbidden.py +19 -24
  40. omlish/os/forkhooks.py +4 -0
  41. omlish/specs/jsonrpc/_marshal.py +33 -24
  42. omlish/specs/openapi/_marshal.py +20 -17
  43. omlish/typedvalues/marshal.py +81 -55
  44. {omlish-0.0.0.dev453.dist-info → omlish-0.0.0.dev454.dist-info}/METADATA +1 -1
  45. {omlish-0.0.0.dev453.dist-info → omlish-0.0.0.dev454.dist-info}/RECORD +49 -48
  46. omlish/marshal/composite/unions.py +0 -213
  47. omlish/marshal/factories/match.py +0 -34
  48. omlish/marshal/factories/simple.py +0 -28
  49. {omlish-0.0.0.dev453.dist-info → omlish-0.0.0.dev454.dist-info}/WHEEL +0 -0
  50. {omlish-0.0.0.dev453.dist-info → omlish-0.0.0.dev454.dist-info}/entry_points.txt +0 -0
  51. {omlish-0.0.0.dev453.dist-info → omlish-0.0.0.dev454.dist-info}/licenses/LICENSE +0 -0
  52. {omlish-0.0.0.dev453.dist-info → omlish-0.0.0.dev454.dist-info}/top_level.txt +0 -0
@@ -22,10 +22,10 @@ from .composite.optionals import OptionalMarshalerFactory
22
22
  from .composite.optionals import OptionalUnmarshalerFactory
23
23
  from .composite.special import SequenceNotStrMarshalerFactory
24
24
  from .composite.special import SequenceNotStrUnmarshalerFactory
25
- from .composite.unions import LiteralUnionMarshalerFactory
26
- from .composite.unions import LiteralUnionUnmarshalerFactory
27
- from .composite.unions import PrimitiveUnionMarshalerFactory
28
- from .composite.unions import PrimitiveUnionUnmarshalerFactory
25
+ from .composite.unions.literals import LiteralUnionMarshalerFactory
26
+ from .composite.unions.literals import LiteralUnionUnmarshalerFactory
27
+ from .composite.unions.primitives import PrimitiveUnionMarshalerFactory
28
+ from .composite.unions.primitives import PrimitiveUnionUnmarshalerFactory
29
29
  from .factories.invalidate import InvalidatableMarshalerFactory
30
30
  from .factories.invalidate import InvalidatableUnmarshalerFactory
31
31
  from .factories.moduleimport.factories import ModuleImportingMarshalerFactory
@@ -119,11 +119,11 @@ def new_standard_marshaler_factory(
119
119
  nonlocal gl
120
120
  gl = DEFAULT_STANDARD_FACTORIES
121
121
 
122
- fi: MarshalerFactory = MultiMarshalerFactory([
122
+ fi: MarshalerFactory = MultiMarshalerFactory(
123
123
  *(first if first is not None else []),
124
124
  *gl.marshaler_factories,
125
125
  *(last if last is not None else []),
126
- ])
126
+ )
127
127
 
128
128
  fi = RecursiveMarshalerFactory(fi)
129
129
 
@@ -152,11 +152,11 @@ def new_standard_unmarshaler_factory(
152
152
  nonlocal gl
153
153
  gl = DEFAULT_STANDARD_FACTORIES
154
154
 
155
- fi: UnmarshalerFactory = MultiUnmarshalerFactory([
155
+ fi: UnmarshalerFactory = MultiUnmarshalerFactory(
156
156
  *(first if first is not None else []),
157
157
  *gl.unmarshaler_factories,
158
158
  *(last if last is not None else []),
159
- ])
159
+ )
160
160
 
161
161
  fi = RecursiveUnmarshalerFactory(fi)
162
162
 
@@ -2,45 +2,40 @@ import dataclasses as dc
2
2
  import typing as ta
3
3
 
4
4
  from ... import reflect as rfl
5
- from ...funcs import match as mfs
6
5
  from ..base.contexts import MarshalContext
7
6
  from ..base.contexts import UnmarshalContext
8
7
  from ..base.errors import ForbiddenTypeError
9
8
  from ..base.types import Marshaler
9
+ from ..base.types import MarshalerFactory
10
10
  from ..base.types import Unmarshaler
11
- from ..factories.simple import SimpleMarshalerFactory
12
- from ..factories.simple import SimpleUnmarshalerFactory
13
-
14
-
15
- C = ta.TypeVar('C')
16
- R = ta.TypeVar('R')
11
+ from ..base.types import UnmarshalerFactory
17
12
 
18
13
 
19
14
  ##
20
15
 
21
16
 
22
17
  @dc.dataclass(frozen=True)
23
- class ForbiddenTypeFactory(mfs.MatchFn[[C, rfl.Type], R]):
18
+ class ForbiddenTypeMarshalerFactoryUnmarshalerFactory(MarshalerFactory, UnmarshalerFactory):
24
19
  rtys: ta.AbstractSet[rfl.Type]
25
20
 
26
- def guard(self, ctx: C, rty: rfl.Type) -> bool:
27
- return rty in self.rtys
21
+ def make_marshaler(self, ctx: MarshalContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
22
+ if rty not in self.rtys:
23
+ return None
28
24
 
29
- def fn(self, ctx: C, rty: rfl.Type) -> R:
30
- raise ForbiddenTypeError(rty)
25
+ def inner():
26
+ raise ForbiddenTypeError(rty)
31
27
 
28
+ return inner
32
29
 
33
- @dc.dataclass(frozen=True)
34
- class ForbiddenTypeMarshalerFactory(
35
- ForbiddenTypeFactory[MarshalContext, Marshaler],
36
- SimpleMarshalerFactory,
37
- ):
38
- pass
30
+ def make_unmarshaler(self, ctx: UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
31
+ if rty not in self.rtys:
32
+ return None
39
33
 
34
+ def inner():
35
+ raise ForbiddenTypeError(rty)
40
36
 
41
- @dc.dataclass(frozen=True)
42
- class ForbiddenTypeUnmarshalerFactory(
43
- ForbiddenTypeFactory[UnmarshalContext, Unmarshaler],
44
- SimpleUnmarshalerFactory,
45
- ):
46
- pass
37
+ return inner
38
+
39
+
40
+ ForbiddenTypeMarshalerFactory = ForbiddenTypeMarshalerFactoryUnmarshalerFactory
41
+ ForbiddenTypeUnmarshalerFactory = ForbiddenTypeMarshalerFactoryUnmarshalerFactory
omlish/os/forkhooks.py CHANGED
@@ -1,5 +1,9 @@
1
1
  # ruff: noqa: UP006 UP007 UP045
2
2
  # @omlish-lite
3
+ """
4
+ TODO:
5
+ - https://github.com/python/cpython/issues/50970
6
+ """
3
7
  import os
4
8
  import threading
5
9
  import typing as ta
@@ -5,7 +5,6 @@ from ... import dataclasses as dc
5
5
  from ... import lang
6
6
  from ... import marshal as msh
7
7
  from ... import reflect as rfl
8
- from ...funcs import match as mfs
9
8
  from .types import NotSpecified
10
9
 
11
10
 
@@ -25,29 +24,39 @@ class NotSpecifiedUnionMarshaler(msh.Marshaler):
25
24
  return self.m.marshal(ctx, o)
26
25
 
27
26
 
28
- class NotSpecifiedUnionMarshalerFactory(msh.MarshalerFactoryMatchClass):
29
- @mfs.simple(lambda _, ctx, rty: (
30
- isinstance(rty, rfl.Union) and
31
- not rty.is_optional and
32
- _NOT_SPECIFIED_RTY in rty.args
33
- ))
34
- def _build(self, ctx: msh.MarshalContext, rty: rfl.Type) -> msh.Marshaler:
35
- args = set(check.isinstance(rty, rfl.Union).args) - {_NOT_SPECIFIED_RTY}
36
- nty = rfl.type_(ta.Union[*args])
37
- m = ctx.make(nty)
38
- return NotSpecifiedUnionMarshaler(m)
39
-
40
-
41
- class NotSpecifiedUnionUnmarshalerFactory(msh.UnmarshalerFactoryMatchClass):
42
- @mfs.simple(lambda _, ctx, rty: (
43
- isinstance(rty, rfl.Union) and
44
- not rty.is_optional and
45
- _NOT_SPECIFIED_RTY in rty.args
46
- ))
47
- def _build(self, ctx: msh.UnmarshalContext, rty: rfl.Type) -> msh.Unmarshaler:
48
- args = set(check.isinstance(rty, rfl.Union).args) - {_NOT_SPECIFIED_RTY}
49
- nty = rfl.type_(ta.Union[*args])
50
- return ctx.make(nty)
27
+ class NotSpecifiedUnionMarshalerFactory(msh.MarshalerFactory):
28
+ def make_marshaler(self, ctx: msh.MarshalContext, rty: rfl.Type) -> ta.Callable[[], msh.Marshaler] | None:
29
+ if not (
30
+ isinstance(rty, rfl.Union) and
31
+ not rty.is_optional and
32
+ _NOT_SPECIFIED_RTY in rty.args
33
+ ):
34
+ return None
35
+
36
+ def inner() -> msh.Marshaler:
37
+ args = set(check.isinstance(rty, rfl.Union).args) - {_NOT_SPECIFIED_RTY}
38
+ nty = rfl.type_(ta.Union[*args])
39
+ m = ctx.make(nty)
40
+ return NotSpecifiedUnionMarshaler(m)
41
+
42
+ return inner
43
+
44
+
45
+ class NotSpecifiedUnionUnmarshalerFactory(msh.UnmarshalerFactory):
46
+ def make_unmarshaler(self, ctx: msh.UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], msh.Unmarshaler] | None:
47
+ if not (
48
+ isinstance(rty, rfl.Union) and
49
+ not rty.is_optional and
50
+ _NOT_SPECIFIED_RTY in rty.args
51
+ ):
52
+ return None
53
+
54
+ def inner() -> msh.Unmarshaler:
55
+ args = set(check.isinstance(rty, rfl.Union).args) - {_NOT_SPECIFIED_RTY}
56
+ nty = rfl.type_(ta.Union[*args])
57
+ return ctx.make(nty)
58
+
59
+ return inner
51
60
 
52
61
 
53
62
  @lang.static_init
@@ -5,7 +5,6 @@ from ... import dataclasses as dc
5
5
  from ... import lang
6
6
  from ... import marshal as msh
7
7
  from ... import reflect as rfl
8
- from ...funcs import match as mfs
9
8
  from .. import jsonschema as jsch
10
9
  from .openapi import Reference
11
10
  from .openapi import Schema
@@ -36,10 +35,11 @@ class _ReferenceUnionMarshaler(msh.Marshaler):
36
35
  return self.m.marshal(ctx, o)
37
36
 
38
37
 
39
- class _ReferenceUnionMarshalerFactory(msh.MarshalerFactoryMatchClass):
40
- @mfs.simple(lambda _, ctx, rty: _reference_union_arg(rty) is not None)
41
- def _build(self, ctx: msh.MarshalContext, rty: rfl.Type) -> msh.Marshaler:
42
- return _ReferenceUnionMarshaler(ctx.make(check.not_none(_reference_union_arg(rty))), ctx.make(Reference))
38
+ class _ReferenceUnionMarshalerFactory(msh.MarshalerFactory):
39
+ def make_marshaler(self, ctx: msh.MarshalContext, rty: rfl.Type) -> ta.Callable[[], msh.Marshaler] | None:
40
+ if (rua := _reference_union_arg(rty)) is None:
41
+ return None
42
+ return lambda: _ReferenceUnionMarshaler(ctx.make(check.not_none(rua)), ctx.make(Reference))
43
43
 
44
44
 
45
45
  #
@@ -59,10 +59,11 @@ class _ReferenceUnionUnmarshaler(msh.Unmarshaler):
59
59
  return self.u.unmarshal(ctx, v) # noqa
60
60
 
61
61
 
62
- class _ReferenceUnionUnmarshalerFactory(msh.UnmarshalerFactoryMatchClass):
63
- @mfs.simple(lambda _, ctx, rty: _reference_union_arg(rty) is not None)
64
- def _build(self, ctx: msh.UnmarshalContext, rty: rfl.Type) -> msh.Unmarshaler:
65
- return _ReferenceUnionUnmarshaler(ctx.make(check.not_none(_reference_union_arg(rty))), ctx.make(Reference))
62
+ class _ReferenceUnionUnmarshalerFactory(msh.UnmarshalerFactory):
63
+ def make_unmarshaler(self, ctx: msh.UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], msh.Unmarshaler] | None:
64
+ if (rua := _reference_union_arg(rty)) is None:
65
+ return None
66
+ return lambda: _ReferenceUnionUnmarshaler(ctx.make(check.not_none(rua)), ctx.make(Reference))
66
67
 
67
68
 
68
69
  ##
@@ -86,10 +87,11 @@ class _SchemaMarshaler(msh.Marshaler):
86
87
  return dct
87
88
 
88
89
 
89
- class _SchemaMarshalerFactory(msh.MarshalerFactoryMatchClass):
90
- @mfs.simple(lambda _, ctx, rty: rty is Schema)
91
- def _build(self, ctx: msh.MarshalContext, rty: rfl.Type) -> msh.Marshaler:
92
- return _SchemaMarshaler(
90
+ class _SchemaMarshalerFactory(msh.MarshalerFactory):
91
+ def make_marshaler(self, ctx: msh.MarshalContext, rty: rfl.Type) -> ta.Callable[[], msh.Marshaler] | None:
92
+ if rty is not Schema:
93
+ return None
94
+ return lambda: _SchemaMarshaler(
93
95
  {
94
96
  f: (msh.translate_name(f, msh.Naming.LOW_CAMEL), ctx.make(rfl.type_(a)))
95
97
  for f, a in dc.reflect(Schema).field_annotations.items()
@@ -121,10 +123,11 @@ class _SchemaUnmarshaler(msh.Unmarshaler):
121
123
  return Schema(**kw)
122
124
 
123
125
 
124
- class _SchemaUnmarshalerFactory(msh.UnmarshalerFactoryMatchClass):
125
- @mfs.simple(lambda _, ctx, rty: rty is Schema)
126
- def _build(self, ctx: msh.UnmarshalContext, rty: rfl.Type) -> msh.Unmarshaler:
127
- return _SchemaUnmarshaler(
126
+ class _SchemaUnmarshalerFactory(msh.UnmarshalerFactory):
127
+ def make_unmarshaler(self, ctx: msh.UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], msh.Unmarshaler] | None:
128
+ if rty is not Schema:
129
+ return None
130
+ return lambda: _SchemaUnmarshaler(
128
131
  {
129
132
  msh.translate_name(f, msh.Naming.LOW_CAMEL): (f, ctx.make(rfl.type_(a)))
130
133
  for f, a in dc.reflect(Schema).field_annotations.items()
@@ -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.MarshalerFactoryMatchClass):
27
- @mfs.simple(lambda _, ctx, rty: (
28
- isinstance(rty, type) and
29
- issubclass(rty, ScalarTypedValue) and
30
- not lang.is_abstract_class(rty)
31
- ))
32
- def _build_scalar(self, ctx: msh.MarshalContext, rty: rfl.Type) -> msh.Marshaler:
33
- dc_rfl = dc.reflect(check.isinstance(rty, type))
34
- v_rty = check.single(dc_rfl.fields_inspection.generic_replaced_field_annotations.values())
35
- v_m = ctx.make(v_rty)
36
- return msh.WrappedMarshaler(lambda _, o: o.v, v_m)
37
-
38
- @mfs.simple(lambda _, ctx, rty: (
39
- isinstance(rty, type) and
40
- issubclass(rty, TypedValue) and
41
- lang.is_abstract_class(rty)
42
- ))
43
- def _build_abstract(self, ctx: msh.MarshalContext, rty: rfl.Type) -> msh.Marshaler:
44
- return msh.make_polymorphism_marshaler(
27
+ class TypedValueMarshalerFactory(msh.MarshalerFactoryMethodClass):
28
+ @msh.MarshalerFactoryMethodClass.make_marshaler.register
29
+ def _make_scalar(self, ctx: msh.MarshalContext, 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(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.MarshalContext, 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.UnmarshalerFactoryMatchClass):
52
- @mfs.simple(lambda _, ctx, rty: (
53
- isinstance(rty, type) and
54
- issubclass(rty, ScalarTypedValue) and
55
- not lang.is_abstract_class(rty)
56
- ))
57
- def _build_scalar(self, ctx: msh.UnmarshalContext, rty: rfl.Type) -> msh.Unmarshaler:
58
- rty = check.isinstance(rty, type)
59
- dc_rfl = dc.reflect(rty)
60
- v_rty = check.single(dc_rfl.fields_inspection.generic_replaced_field_annotations.values())
61
- v_u = ctx.make(v_rty)
62
- return msh.WrappedUnmarshaler(lambda _, v: rty(v), v_u)
63
-
64
- @mfs.simple(lambda _, ctx, rty: (
65
- isinstance(rty, type) and
66
- issubclass(rty, TypedValue) and
67
- lang.is_abstract_class(rty)
68
- ))
69
- def _build_abstract(self, ctx: msh.UnmarshalContext, rty: rfl.Type) -> msh.Unmarshaler:
70
- return msh.make_polymorphism_unmarshaler(
61
+ class TypedValueUnmarshalerFactory(msh.UnmarshalerFactoryMethodClass):
62
+ @msh.UnmarshalerFactoryMethodClass.make_unmarshaler.register
63
+ def _make_scalar(self, ctx: msh.UnmarshalContext, 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(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.UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], msh.Unmarshaler] | None:
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,
@@ -108,14 +126,18 @@ 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.MarshalerFactoryMatchClass):
112
- @mfs.simple(lambda _, ctx, rty: isinstance(rty, rfl.Generic) and rty.cls is TypedValues)
113
- def _build(self, ctx: msh.MarshalContext, rty: rfl.Type) -> msh.Marshaler:
114
- return build_typed_values_marshaler(ctx, rty)
129
+ class TypedValuesMarshalerFactory(msh.MarshalerFactoryMethodClass):
130
+ @msh.MarshalerFactoryMethodClass.make_marshaler.register
131
+ def _make_generic(self, ctx: msh.MarshalContext, 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
- @mfs.simple(lambda _, ctx, rty: rty is TypedValues)
117
- def _build_concrete(self, ctx: msh.MarshalContext, rty: rfl.Type) -> msh.Marshaler:
118
- raise NotImplementedError
136
+ @msh.MarshalerFactoryMethodClass.make_marshaler.register
137
+ def _make_concrete(self, ctx: msh.MarshalContext, 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
  #
@@ -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.UnmarshalerFactoryMatchClass):
134
- @mfs.simple(lambda _, ctx, rty: isinstance(rty, rfl.Generic) and rty.cls is TypedValues)
135
- def _build(self, ctx: msh.UnmarshalContext, rty: rfl.Type) -> msh.Unmarshaler:
136
- return build_typed_values_unmarshaler(ctx, rty)
155
+ class TypedValuesUnmarshalerFactory(msh.UnmarshalerFactoryMethodClass):
156
+ @msh.UnmarshalerFactoryMethodClass.make_unmarshaler.register
157
+ def _build(self, ctx: msh.UnmarshalContext, 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
- @mfs.simple(lambda _, ctx, rty: rty is TypedValues)
139
- def _build_concrete(self, ctx: msh.UnmarshalContext, rty: rfl.Type) -> msh.Unmarshaler:
140
- raise NotImplementedError
162
+ @msh.UnmarshalerFactoryMethodClass.make_unmarshaler.register
163
+ def _build_concrete(self, ctx: msh.UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], msh.Unmarshaler] | None:
164
+ if rty is not TypedValues:
165
+ return None
166
+ return lambda: lang.raise_(NotImplementedError())
141
167
 
142
168
 
143
169
  ##
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: omlish
3
- Version: 0.0.0.dev453
3
+ Version: 0.0.0.dev454
4
4
  Summary: omlish
5
5
  Author: wrmsr
6
6
  License-Expression: BSD-3-Clause