omlish 0.0.0.dev454__py3-none-any.whl → 0.0.0.dev456__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/lang/__init__.py +7 -1
- omlish/lang/functions.py +2 -2
- omlish/lang/iterables.py +0 -8
- omlish/lang/sequences.py +124 -0
- omlish/marshal/__init__.py +6 -0
- omlish/marshal/base/configs.py +12 -0
- omlish/marshal/base/contexts.py +32 -16
- omlish/marshal/base/funcs.py +4 -12
- omlish/marshal/base/options.py +8 -0
- omlish/marshal/base/registries.py +32 -4
- omlish/marshal/base/types.py +27 -13
- omlish/marshal/composite/iterables.py +10 -8
- omlish/marshal/composite/literals.py +6 -4
- omlish/marshal/composite/mappings.py +10 -8
- omlish/marshal/composite/maybes.py +10 -8
- omlish/marshal/composite/newtypes.py +6 -6
- omlish/marshal/composite/optionals.py +6 -4
- omlish/marshal/composite/special.py +6 -6
- omlish/marshal/composite/unions/literals.py +6 -4
- omlish/marshal/composite/unions/primitives.py +6 -4
- omlish/marshal/factories/invalidate.py +4 -4
- omlish/marshal/factories/method.py +4 -6
- omlish/marshal/factories/moduleimport/factories.py +6 -6
- omlish/marshal/factories/multi.py +4 -4
- omlish/marshal/factories/recursive.py +4 -2
- omlish/marshal/factories/typecache.py +4 -9
- omlish/marshal/factories/typemap.py +4 -4
- omlish/marshal/objects/dataclasses.py +30 -16
- omlish/marshal/objects/marshal.py +4 -3
- omlish/marshal/objects/namedtuples.py +6 -6
- omlish/marshal/objects/unmarshal.py +4 -3
- omlish/marshal/polymorphism/marshal.py +4 -3
- omlish/marshal/polymorphism/unions.py +7 -7
- omlish/marshal/polymorphism/unmarshal.py +4 -3
- omlish/marshal/singular/enums.py +4 -2
- omlish/marshal/trivial/any.py +1 -1
- omlish/marshal/trivial/forbidden.py +4 -4
- omlish/specs/jsonrpc/_marshal.py +4 -4
- omlish/specs/openapi/_marshal.py +16 -10
- omlish/typedvalues/marshal.py +14 -14
- {omlish-0.0.0.dev454.dist-info → omlish-0.0.0.dev456.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev454.dist-info → omlish-0.0.0.dev456.dist-info}/RECORD +47 -47
- omlish/funcs/match.py +0 -229
- {omlish-0.0.0.dev454.dist-info → omlish-0.0.0.dev456.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev454.dist-info → omlish-0.0.0.dev456.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev454.dist-info → omlish-0.0.0.dev456.dist-info}/licenses/LICENSE +0 -0
- {omlish-0.0.0.dev454.dist-info → omlish-0.0.0.dev456.dist-info}/top_level.txt +0 -0
@@ -9,7 +9,9 @@ from ... import check
|
|
9
9
|
from ... import lang
|
10
10
|
from ... import reflect as rfl
|
11
11
|
from ..base.contexts import MarshalContext
|
12
|
+
from ..base.contexts import MarshalFactoryContext
|
12
13
|
from ..base.contexts import UnmarshalContext
|
14
|
+
from ..base.contexts import UnmarshalFactoryContext
|
13
15
|
from ..base.types import Marshaler
|
14
16
|
from ..base.types import Unmarshaler
|
15
17
|
from ..base.values import Value
|
@@ -34,16 +36,16 @@ class MaybeMarshaler(Marshaler):
|
|
34
36
|
|
35
37
|
class MaybeMarshalerFactory(MarshalerFactoryMethodClass):
|
36
38
|
@MarshalerFactoryMethodClass.make_marshaler.register
|
37
|
-
def _make_generic(self, ctx:
|
39
|
+
def _make_generic(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
38
40
|
if not (isinstance(rty, rfl.Generic) and rty.cls is lang.Maybe):
|
39
41
|
return None
|
40
|
-
return lambda: MaybeMarshaler(ctx.
|
42
|
+
return lambda: MaybeMarshaler(ctx.make_marshaler(check.single(rty.args)))
|
41
43
|
|
42
44
|
@MarshalerFactoryMethodClass.make_marshaler.register
|
43
|
-
def _make_concrete(self, ctx:
|
45
|
+
def _make_concrete(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
44
46
|
if not (isinstance(rty, type) and issubclass(rty, lang.Maybe)):
|
45
47
|
return None
|
46
|
-
return lambda: MaybeMarshaler(ctx.
|
48
|
+
return lambda: MaybeMarshaler(ctx.make_marshaler(ta.Any))
|
47
49
|
|
48
50
|
|
49
51
|
#
|
@@ -62,13 +64,13 @@ class MaybeUnmarshaler(Unmarshaler):
|
|
62
64
|
|
63
65
|
class MaybeUnmarshalerFactory(UnmarshalerFactoryMethodClass):
|
64
66
|
@UnmarshalerFactoryMethodClass.make_unmarshaler.register
|
65
|
-
def _make_generic(self, ctx:
|
67
|
+
def _make_generic(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
66
68
|
if not (isinstance(rty, rfl.Generic) and rty.cls is lang.Maybe):
|
67
69
|
return None
|
68
|
-
return lambda: MaybeUnmarshaler(ctx.
|
70
|
+
return lambda: MaybeUnmarshaler(ctx.make_unmarshaler(check.single(rty.args)))
|
69
71
|
|
70
72
|
@UnmarshalerFactoryMethodClass.make_unmarshaler.register
|
71
|
-
def _make_concrete(self, ctx:
|
73
|
+
def _make_concrete(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
72
74
|
if not (isinstance(rty, type) and issubclass(rty, lang.Maybe)):
|
73
75
|
return None
|
74
|
-
return lambda: MaybeUnmarshaler(ctx.
|
76
|
+
return lambda: MaybeUnmarshaler(ctx.make_unmarshaler(ta.Any))
|
@@ -2,8 +2,8 @@ import typing as ta
|
|
2
2
|
|
3
3
|
from ... import check
|
4
4
|
from ... import reflect as rfl
|
5
|
-
from ..base.contexts import
|
6
|
-
from ..base.contexts import
|
5
|
+
from ..base.contexts import MarshalFactoryContext
|
6
|
+
from ..base.contexts import UnmarshalFactoryContext
|
7
7
|
from ..base.types import Marshaler
|
8
8
|
from ..base.types import MarshalerFactory
|
9
9
|
from ..base.types import Unmarshaler
|
@@ -14,14 +14,14 @@ from ..base.types import UnmarshalerFactory
|
|
14
14
|
|
15
15
|
|
16
16
|
class NewtypeMarshalerFactory(MarshalerFactory):
|
17
|
-
def make_marshaler(self, ctx:
|
17
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
18
18
|
if not isinstance(rty, rfl.NewType):
|
19
19
|
return None
|
20
|
-
return lambda: ctx.
|
20
|
+
return lambda: ctx.make_marshaler(check.isinstance(rty, rfl.NewType).ty)
|
21
21
|
|
22
22
|
|
23
23
|
class NewtypeUnmarshalerFactory(UnmarshalerFactory):
|
24
|
-
def make_unmarshaler(self, ctx:
|
24
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
25
25
|
if not isinstance(rty, rfl.NewType):
|
26
26
|
return None
|
27
|
-
return lambda: ctx.
|
27
|
+
return lambda: ctx.make_unmarshaler(check.isinstance(rty, rfl.NewType).ty)
|
@@ -4,7 +4,9 @@ import typing as ta
|
|
4
4
|
from ... import check
|
5
5
|
from ... import reflect as rfl
|
6
6
|
from ..base.contexts import MarshalContext
|
7
|
+
from ..base.contexts import MarshalFactoryContext
|
7
8
|
from ..base.contexts import UnmarshalContext
|
9
|
+
from ..base.contexts import UnmarshalFactoryContext
|
8
10
|
from ..base.types import Marshaler
|
9
11
|
from ..base.types import MarshalerFactory
|
10
12
|
from ..base.types import Unmarshaler
|
@@ -26,10 +28,10 @@ class OptionalMarshaler(Marshaler):
|
|
26
28
|
|
27
29
|
|
28
30
|
class OptionalMarshalerFactory(MarshalerFactory):
|
29
|
-
def make_marshaler(self, ctx:
|
31
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
30
32
|
if not (isinstance(rty, rfl.Union) and rty.is_optional):
|
31
33
|
return None
|
32
|
-
return lambda: OptionalMarshaler(ctx.
|
34
|
+
return lambda: OptionalMarshaler(ctx.make_marshaler(check.isinstance(rty, rfl.Union).without_none()))
|
33
35
|
|
34
36
|
|
35
37
|
@dc.dataclass(frozen=True)
|
@@ -43,7 +45,7 @@ class OptionalUnmarshaler(Unmarshaler):
|
|
43
45
|
|
44
46
|
|
45
47
|
class OptionalUnmarshalerFactory(UnmarshalerFactory):
|
46
|
-
def make_unmarshaler(self, ctx:
|
48
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
47
49
|
if not (isinstance(rty, rfl.Union) and rty.is_optional):
|
48
50
|
return None
|
49
|
-
return lambda: OptionalUnmarshaler(ctx.
|
51
|
+
return lambda: OptionalUnmarshaler(ctx.make_unmarshaler(check.isinstance(rty, rfl.Union).without_none()))
|
@@ -4,8 +4,8 @@ import typing as ta
|
|
4
4
|
from ... import check
|
5
5
|
from ... import lang
|
6
6
|
from ... import reflect as rfl
|
7
|
-
from ..base.contexts import
|
8
|
-
from ..base.contexts import
|
7
|
+
from ..base.contexts import MarshalFactoryContext
|
8
|
+
from ..base.contexts import UnmarshalFactoryContext
|
9
9
|
from ..base.types import Marshaler
|
10
10
|
from ..base.types import MarshalerFactory
|
11
11
|
from ..base.types import Unmarshaler
|
@@ -19,15 +19,15 @@ from .iterables import IterableUnmarshaler
|
|
19
19
|
|
20
20
|
|
21
21
|
class SequenceNotStrMarshalerFactory(MarshalerFactory):
|
22
|
-
def make_marshaler(self, ctx:
|
22
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
23
23
|
if not (isinstance(rty, rfl.Protocol) and rty.cls is lang.SequenceNotStr):
|
24
24
|
return None
|
25
|
-
return lambda: IterableMarshaler(ctx.
|
25
|
+
return lambda: IterableMarshaler(ctx.make_marshaler(check.single(rty.args)))
|
26
26
|
|
27
27
|
|
28
28
|
class SequenceNotStrUnmarshalerFactory(UnmarshalerFactory):
|
29
|
-
def make_unmarshaler(self, ctx:
|
29
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
30
30
|
if not (isinstance(rty, rfl.Protocol) and rty.cls is lang.SequenceNotStr):
|
31
31
|
return None
|
32
32
|
cty = DEFAULT_ITERABLE_CONCRETE_TYPES[collections.abc.Sequence] # type: ignore[type-abstract]
|
33
|
-
return lambda: IterableUnmarshaler(cty, ctx.
|
33
|
+
return lambda: IterableUnmarshaler(cty, ctx.make_unmarshaler(check.single(rty.args)))
|
@@ -6,7 +6,9 @@ from .... import dataclasses as dc
|
|
6
6
|
from .... import lang
|
7
7
|
from .... import reflect as rfl
|
8
8
|
from ...base.contexts import MarshalContext
|
9
|
+
from ...base.contexts import MarshalFactoryContext
|
9
10
|
from ...base.contexts import UnmarshalContext
|
11
|
+
from ...base.contexts import UnmarshalFactoryContext
|
10
12
|
from ...base.types import Marshaler
|
11
13
|
from ...base.types import MarshalerFactory
|
12
14
|
from ...base.types import Unmarshaler
|
@@ -62,10 +64,10 @@ class LiteralUnionMarshaler(Marshaler):
|
|
62
64
|
|
63
65
|
|
64
66
|
class LiteralUnionMarshalerFactory(MarshalerFactory):
|
65
|
-
def make_marshaler(self, ctx:
|
67
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
66
68
|
if (ds := _destructure_literal_union_type(rty)) is None:
|
67
69
|
return None
|
68
|
-
return lambda: LiteralUnionMarshaler(ds.v_ty, ctx.
|
70
|
+
return lambda: LiteralUnionMarshaler(ds.v_ty, ctx.make_marshaler(ds.lit), ctx.make_marshaler(ds.non_lit))
|
69
71
|
|
70
72
|
|
71
73
|
#
|
@@ -85,7 +87,7 @@ class LiteralUnionUnmarshaler(Unmarshaler):
|
|
85
87
|
|
86
88
|
|
87
89
|
class LiteralUnionUnmarshalerFactory(UnmarshalerFactory):
|
88
|
-
def make_unmarshaler(self, ctx:
|
90
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
89
91
|
if (ds := _destructure_literal_union_type(rty)) is None:
|
90
92
|
return None
|
91
|
-
return lambda: LiteralUnionUnmarshaler(ds.v_ty, ctx.
|
93
|
+
return lambda: LiteralUnionUnmarshaler(ds.v_ty, ctx.make_unmarshaler(ds.lit), ctx.make_unmarshaler(ds.non_lit))
|
@@ -5,7 +5,9 @@ from .... import collections as col
|
|
5
5
|
from .... import dataclasses as dc
|
6
6
|
from .... import reflect as rfl
|
7
7
|
from ...base.contexts import MarshalContext
|
8
|
+
from ...base.contexts import MarshalFactoryContext
|
8
9
|
from ...base.contexts import UnmarshalContext
|
10
|
+
from ...base.contexts import UnmarshalFactoryContext
|
9
11
|
from ...base.types import Marshaler
|
10
12
|
from ...base.types import MarshalerFactory
|
11
13
|
from ...base.types import Unmarshaler
|
@@ -63,12 +65,12 @@ class PrimitiveUnionMarshaler(Marshaler):
|
|
63
65
|
class PrimitiveUnionMarshalerFactory(MarshalerFactory):
|
64
66
|
tys: ta.Sequence[type] = PRIMITIVE_UNION_TYPES
|
65
67
|
|
66
|
-
def make_marshaler(self, ctx:
|
68
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
67
69
|
if (ds := _destructure_primitive_union_type(rty, self.tys)) is None:
|
68
70
|
return None
|
69
71
|
return lambda: PrimitiveUnionMarshaler(
|
70
72
|
ds.prim,
|
71
|
-
ctx.
|
73
|
+
ctx.make_marshaler(check.single(ds.non_prim)) if ds.non_prim else None,
|
72
74
|
)
|
73
75
|
|
74
76
|
|
@@ -92,10 +94,10 @@ class PrimitiveUnionUnmarshaler(Unmarshaler):
|
|
92
94
|
class PrimitiveUnionUnmarshalerFactory(UnmarshalerFactory):
|
93
95
|
tys: ta.Sequence[type] = PRIMITIVE_UNION_TYPES
|
94
96
|
|
95
|
-
def make_unmarshaler(self, ctx:
|
97
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
96
98
|
if (ds := _destructure_primitive_union_type(rty, self.tys)) is None:
|
97
99
|
return None
|
98
100
|
return lambda: PrimitiveUnionUnmarshaler(
|
99
101
|
ds.prim,
|
100
|
-
ctx.
|
102
|
+
ctx.make_unmarshaler(check.single(ds.non_prim)) if ds.non_prim else None,
|
101
103
|
)
|
@@ -2,8 +2,8 @@ import threading
|
|
2
2
|
import typing as ta
|
3
3
|
|
4
4
|
from ... import reflect as rfl
|
5
|
-
from ..base.contexts import
|
6
|
-
from ..base.contexts import
|
5
|
+
from ..base.contexts import MarshalFactoryContext
|
6
|
+
from ..base.contexts import UnmarshalFactoryContext
|
7
7
|
from ..base.types import Marshaler
|
8
8
|
from ..base.types import MarshalerFactory
|
9
9
|
from ..base.types import Unmarshaler
|
@@ -59,10 +59,10 @@ class _InvalidatableFactory(ta.Generic[FactoryT]):
|
|
59
59
|
|
60
60
|
|
61
61
|
class InvalidatableMarshalerFactory(_InvalidatableFactory[MarshalerFactory], MarshalerFactory):
|
62
|
-
def make_marshaler(self, ctx:
|
62
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
63
63
|
return self._fac().make_marshaler(ctx, rty)
|
64
64
|
|
65
65
|
|
66
66
|
class InvalidatableUnmarshalerFactory(_InvalidatableFactory[UnmarshalerFactory], UnmarshalerFactory):
|
67
|
-
def make_unmarshaler(self, ctx:
|
67
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
68
68
|
return self._fac().make_unmarshaler(ctx, rty)
|
@@ -3,8 +3,8 @@ import typing as ta
|
|
3
3
|
from ... import lang
|
4
4
|
from ... import reflect as rfl
|
5
5
|
from ...funcs import guard as gfs
|
6
|
-
from ..base.contexts import
|
7
|
-
from ..base.contexts import
|
6
|
+
from ..base.contexts import MarshalFactoryContext
|
7
|
+
from ..base.contexts import UnmarshalFactoryContext
|
8
8
|
from ..base.types import Marshaler
|
9
9
|
from ..base.types import MarshalerFactory
|
10
10
|
from ..base.types import Unmarshaler
|
@@ -15,14 +15,12 @@ from ..base.types import UnmarshalerFactory
|
|
15
15
|
|
16
16
|
|
17
17
|
class MarshalerFactoryMethodClass(MarshalerFactory, lang.Abstract):
|
18
|
-
@ta.final
|
19
18
|
@gfs.method(instance_cache=True)
|
20
|
-
def make_marshaler(self, ctx:
|
19
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
21
20
|
raise NotImplementedError
|
22
21
|
|
23
22
|
|
24
23
|
class UnmarshalerFactoryMethodClass(UnmarshalerFactory, lang.Abstract):
|
25
|
-
@ta.final
|
26
24
|
@gfs.method(instance_cache=True)
|
27
|
-
def make_unmarshaler(self, ctx:
|
25
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
28
26
|
raise NotImplementedError
|
@@ -12,8 +12,8 @@ import typing as ta
|
|
12
12
|
|
13
13
|
from .... import reflect as rfl
|
14
14
|
from ...base.contexts import BaseContext
|
15
|
-
from ...base.contexts import
|
16
|
-
from ...base.contexts import
|
15
|
+
from ...base.contexts import MarshalFactoryContext
|
16
|
+
from ...base.contexts import UnmarshalFactoryContext
|
17
17
|
from ...base.types import Marshaler
|
18
18
|
from ...base.types import MarshalerFactory
|
19
19
|
from ...base.types import Unmarshaler
|
@@ -52,20 +52,20 @@ class _ModuleImportingFactory(ta.Generic[FactoryT]):
|
|
52
52
|
self._callback()
|
53
53
|
|
54
54
|
def _import_if_necessary(self, ctx: BaseContext) -> None:
|
55
|
-
if (mis := ctx.
|
55
|
+
if (mis := ctx.configs.get_of(None, ModuleImport)) and mis is not self._last_mis:
|
56
56
|
with self._lock:
|
57
|
-
if (mis := ctx.
|
57
|
+
if (mis := ctx.configs.get_of(None, ModuleImport)) and mis is not self._last_mis:
|
58
58
|
self._do_import(ctx, mis)
|
59
59
|
self._last_mis = mis
|
60
60
|
|
61
61
|
|
62
62
|
class ModuleImportingMarshalerFactory(_ModuleImportingFactory[MarshalerFactory], MarshalerFactory):
|
63
|
-
def make_marshaler(self, ctx:
|
63
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
64
64
|
self._import_if_necessary(ctx)
|
65
65
|
return self._fac.make_marshaler(ctx, rty)
|
66
66
|
|
67
67
|
|
68
68
|
class ModuleImportingUnmarshalerFactory(_ModuleImportingFactory[UnmarshalerFactory], UnmarshalerFactory):
|
69
|
-
def make_unmarshaler(self, ctx:
|
69
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
70
70
|
self._import_if_necessary(ctx)
|
71
71
|
return self._fac.make_unmarshaler(ctx, rty)
|
@@ -2,8 +2,8 @@ import typing as ta
|
|
2
2
|
|
3
3
|
from ... import reflect as rfl
|
4
4
|
from ...funcs import guard as gfs
|
5
|
-
from ..base.contexts import
|
6
|
-
from ..base.contexts import
|
5
|
+
from ..base.contexts import MarshalFactoryContext
|
6
|
+
from ..base.contexts import UnmarshalFactoryContext
|
7
7
|
from ..base.types import Marshaler
|
8
8
|
from ..base.types import MarshalerFactory
|
9
9
|
from ..base.types import Unmarshaler
|
@@ -24,7 +24,7 @@ class MultiMarshalerFactory(MarshalerFactory):
|
|
24
24
|
self._facs = facs
|
25
25
|
self._mgf = gfs.multi(*[f.make_marshaler for f in self._facs], strict=strict)
|
26
26
|
|
27
|
-
def make_marshaler(self, ctx:
|
27
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
28
28
|
return self._mgf(ctx, rty)
|
29
29
|
|
30
30
|
|
@@ -39,5 +39,5 @@ class MultiUnmarshalerFactory(UnmarshalerFactory):
|
|
39
39
|
self._facs = facs
|
40
40
|
self._mgf = gfs.multi(*[f.make_unmarshaler for f in self._facs], strict=strict)
|
41
41
|
|
42
|
-
def make_unmarshaler(self, ctx:
|
42
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
43
43
|
return self._mgf(ctx, rty)
|
@@ -2,7 +2,9 @@ import typing as ta
|
|
2
2
|
|
3
3
|
from ... import reflect as rfl
|
4
4
|
from ..base.contexts import MarshalContext
|
5
|
+
from ..base.contexts import MarshalFactoryContext
|
5
6
|
from ..base.contexts import UnmarshalContext
|
7
|
+
from ..base.contexts import UnmarshalFactoryContext
|
6
8
|
from ..base.types import Marshaler
|
7
9
|
from ..base.types import MarshalerFactory
|
8
10
|
from ..base.types import Unmarshaler
|
@@ -80,7 +82,7 @@ class RecursiveMarshalerFactory(_RecursiveFactory[MarshalerFactory], MarshalerFa
|
|
80
82
|
def __init__(self, fac: MarshalerFactory) -> None:
|
81
83
|
super().__init__(fac, _ProxyMarshaler._new) # noqa
|
82
84
|
|
83
|
-
def make_marshaler(self, ctx:
|
85
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
84
86
|
if (m := self._fac.make_marshaler(ctx, rty)) is None:
|
85
87
|
return None
|
86
88
|
return self._wrap(m, rty)
|
@@ -98,7 +100,7 @@ class RecursiveUnmarshalerFactory(_RecursiveFactory[UnmarshalerFactory], Unmarsh
|
|
98
100
|
def __init__(self, fac: UnmarshalerFactory) -> None:
|
99
101
|
super().__init__(fac, _ProxyUnmarshaler._new) # noqa
|
100
102
|
|
101
|
-
def make_unmarshaler(self, ctx:
|
103
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
102
104
|
if (m := self._fac.make_unmarshaler(ctx, rty)) is None:
|
103
105
|
return None
|
104
106
|
return self._wrap(m, rty)
|
@@ -1,15 +1,10 @@
|
|
1
|
-
"""
|
2
|
-
FIXME:
|
3
|
-
- fix Context lifetime broken design already
|
4
|
-
- obvious: FactoryContext
|
5
|
-
"""
|
6
1
|
import threading
|
7
2
|
import typing as ta
|
8
3
|
|
9
4
|
from ... import check
|
10
5
|
from ... import reflect as rfl
|
11
|
-
from ..base.contexts import
|
12
|
-
from ..base.contexts import
|
6
|
+
from ..base.contexts import MarshalFactoryContext
|
7
|
+
from ..base.contexts import UnmarshalFactoryContext
|
13
8
|
from ..base.types import Marshaler
|
14
9
|
from ..base.types import MarshalerFactory
|
15
10
|
from ..base.types import Unmarshaler
|
@@ -50,10 +45,10 @@ class _TypeCacheFactory(ta.Generic[FactoryT]):
|
|
50
45
|
|
51
46
|
|
52
47
|
class TypeCacheMarshalerFactory(_TypeCacheFactory[MarshalerFactory], MarshalerFactory):
|
53
|
-
def make_marshaler(self, ctx:
|
48
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
54
49
|
return self._make(rty, lambda: self._fac.make_marshaler(ctx, rty))
|
55
50
|
|
56
51
|
|
57
52
|
class TypeCacheUnmarshalerFactory(_TypeCacheFactory[UnmarshalerFactory], UnmarshalerFactory):
|
58
|
-
def make_unmarshaler(self, ctx:
|
53
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
59
54
|
return self._make(rty, lambda: self._fac.make_unmarshaler(ctx, rty))
|
@@ -3,8 +3,8 @@ import typing as ta
|
|
3
3
|
from ... import check
|
4
4
|
from ... import dataclasses as dc
|
5
5
|
from ... import reflect as rfl
|
6
|
-
from ..base.contexts import
|
7
|
-
from ..base.contexts import
|
6
|
+
from ..base.contexts import MarshalFactoryContext
|
7
|
+
from ..base.contexts import UnmarshalFactoryContext
|
8
8
|
from ..base.types import Marshaler
|
9
9
|
from ..base.types import MarshalerFactory
|
10
10
|
from ..base.types import Unmarshaler
|
@@ -24,7 +24,7 @@ class TypeMapMarshalerFactory(MarshalerFactory):
|
|
24
24
|
},
|
25
25
|
)
|
26
26
|
|
27
|
-
def make_marshaler(self, ctx:
|
27
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
28
28
|
check.isinstance(rty, rfl.TYPES)
|
29
29
|
try:
|
30
30
|
m = self.m[rty]
|
@@ -49,7 +49,7 @@ class TypeMapUnmarshalerFactory(UnmarshalerFactory):
|
|
49
49
|
},
|
50
50
|
)
|
51
51
|
|
52
|
-
def make_unmarshaler(self, ctx:
|
52
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
53
53
|
check.isinstance(rty, rfl.TYPES)
|
54
54
|
try:
|
55
55
|
u = self.u[rty]
|
@@ -11,8 +11,8 @@ from ... import dataclasses as dc
|
|
11
11
|
from ... import lang
|
12
12
|
from ... import reflect as rfl
|
13
13
|
from ...lite import marshal as lm
|
14
|
-
from ..base.contexts import
|
15
|
-
from ..base.contexts import
|
14
|
+
from ..base.contexts import MarshalFactoryContext
|
15
|
+
from ..base.contexts import UnmarshalFactoryContext
|
16
16
|
from ..base.errors import UnhandledTypeError
|
17
17
|
from ..base.options import Option
|
18
18
|
from ..base.types import Marshaler
|
@@ -160,22 +160,38 @@ def get_dataclass_field_infos(
|
|
160
160
|
return FieldInfos(ret)
|
161
161
|
|
162
162
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
163
|
+
##
|
164
|
+
|
165
|
+
|
166
|
+
def _make_field_marshal_obj(
|
167
|
+
ctx: MarshalFactoryContext,
|
168
|
+
ty: ta.Any,
|
169
|
+
obj: Marshaler | None,
|
170
|
+
fac: MarshalerFactory | None,
|
169
171
|
):
|
170
172
|
if obj is not None:
|
171
173
|
return obj
|
172
174
|
if fac is not None:
|
173
|
-
if (m :=
|
175
|
+
if (m := fac.make_marshaler(ctx, ty)) is None:
|
174
176
|
raise UnhandledTypeError(ty)
|
175
177
|
return m()
|
176
|
-
return ctx.
|
178
|
+
return ctx.make_marshaler(ty)
|
177
179
|
|
178
180
|
|
181
|
+
def _make_field_unmarshal_obj(
|
182
|
+
ctx: UnmarshalFactoryContext,
|
183
|
+
ty: ta.Any,
|
184
|
+
obj: Unmarshaler | None,
|
185
|
+
fac: UnmarshalerFactory | None,
|
186
|
+
):
|
187
|
+
if obj is not None:
|
188
|
+
return obj
|
189
|
+
if fac is not None:
|
190
|
+
if (m := fac.make_unmarshaler(ctx, ty)) is None:
|
191
|
+
raise UnhandledTypeError(ty)
|
192
|
+
return m()
|
193
|
+
return ctx.make_unmarshaler(ty)
|
194
|
+
|
179
195
|
##
|
180
196
|
|
181
197
|
|
@@ -204,7 +220,7 @@ def _type_or_generic_base(rty: rfl.Type) -> type | None:
|
|
204
220
|
|
205
221
|
|
206
222
|
class DataclassMarshalerFactory(AbstractDataclassFactory, MarshalerFactory):
|
207
|
-
def make_marshaler(self, ctx:
|
223
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
208
224
|
if not (
|
209
225
|
(ty := _type_or_generic_base(rty)) is not None and
|
210
226
|
dc.is_dataclass(ty) and
|
@@ -223,12 +239,11 @@ class DataclassMarshalerFactory(AbstractDataclassFactory, MarshalerFactory):
|
|
223
239
|
fields = [
|
224
240
|
(
|
225
241
|
fi,
|
226
|
-
|
242
|
+
_make_field_marshal_obj(
|
227
243
|
ctx,
|
228
244
|
fi.type,
|
229
245
|
fi.metadata.marshaler,
|
230
246
|
fi.metadata.marshaler_factory,
|
231
|
-
'make_marshaler',
|
232
247
|
),
|
233
248
|
)
|
234
249
|
for fi in fis
|
@@ -247,7 +262,7 @@ class DataclassMarshalerFactory(AbstractDataclassFactory, MarshalerFactory):
|
|
247
262
|
|
248
263
|
|
249
264
|
class DataclassUnmarshalerFactory(AbstractDataclassFactory, UnmarshalerFactory):
|
250
|
-
def make_unmarshaler(self, ctx:
|
265
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
251
266
|
if not (
|
252
267
|
(ty := _type_or_generic_base(rty)) is not None and
|
253
268
|
dc.is_dataclass(ty) and
|
@@ -287,12 +302,11 @@ class DataclassUnmarshalerFactory(AbstractDataclassFactory, UnmarshalerFactory):
|
|
287
302
|
else:
|
288
303
|
tup = (
|
289
304
|
fi,
|
290
|
-
|
305
|
+
_make_field_unmarshal_obj(
|
291
306
|
ctx,
|
292
307
|
fi.type,
|
293
308
|
fi.metadata.unmarshaler,
|
294
309
|
fi.metadata.unmarshaler_factory,
|
295
|
-
'make_unmarshaler',
|
296
310
|
),
|
297
311
|
)
|
298
312
|
|
@@ -5,6 +5,7 @@ from ... import check
|
|
5
5
|
from ... import dataclasses as dc
|
6
6
|
from ... import reflect as rfl
|
7
7
|
from ..base.contexts import MarshalContext
|
8
|
+
from ..base.contexts import MarshalFactoryContext
|
8
9
|
from ..base.types import Marshaler
|
9
10
|
from ..base.types import MarshalerFactory
|
10
11
|
from ..base.values import Value
|
@@ -29,12 +30,12 @@ class ObjectMarshaler(Marshaler):
|
|
29
30
|
@classmethod
|
30
31
|
def make(
|
31
32
|
cls,
|
32
|
-
ctx:
|
33
|
+
ctx: MarshalFactoryContext,
|
33
34
|
fis: FieldInfos,
|
34
35
|
**kwargs: ta.Any,
|
35
36
|
) -> Marshaler:
|
36
37
|
fields = [
|
37
|
-
(fi, ctx.
|
38
|
+
(fi, ctx.make_marshaler(fi.type))
|
38
39
|
for fi in fis
|
39
40
|
]
|
40
41
|
|
@@ -93,7 +94,7 @@ class SimpleObjectMarshalerFactory(MarshalerFactory):
|
|
93
94
|
|
94
95
|
specials: ObjectSpecials = ObjectSpecials()
|
95
96
|
|
96
|
-
def make_marshaler(self, ctx:
|
97
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
97
98
|
if not (isinstance(rty, type) and rty in self.dct):
|
98
99
|
return None
|
99
100
|
|
@@ -5,8 +5,8 @@ from ... import check
|
|
5
5
|
from ... import collections as col
|
6
6
|
from ... import lang
|
7
7
|
from ... import reflect as rfl
|
8
|
-
from ..base.contexts import
|
9
|
-
from ..base.contexts import
|
8
|
+
from ..base.contexts import MarshalFactoryContext
|
9
|
+
from ..base.contexts import UnmarshalFactoryContext
|
10
10
|
from ..base.options import Option
|
11
11
|
from ..base.types import Marshaler
|
12
12
|
from ..base.types import MarshalerFactory
|
@@ -56,7 +56,7 @@ def get_namedtuple_field_infos(
|
|
56
56
|
|
57
57
|
|
58
58
|
class NamedtupleMarshalerFactory(MarshalerFactory):
|
59
|
-
def make_marshaler(self, ctx:
|
59
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
60
60
|
if not _is_namedtuple(rty):
|
61
61
|
return None
|
62
62
|
|
@@ -68,7 +68,7 @@ class NamedtupleMarshalerFactory(MarshalerFactory):
|
|
68
68
|
fis = get_namedtuple_field_infos(ty, ctx.options)
|
69
69
|
|
70
70
|
fields = [
|
71
|
-
(fi, ctx.
|
71
|
+
(fi, ctx.make_marshaler(fi.type))
|
72
72
|
for fi in fis
|
73
73
|
]
|
74
74
|
|
@@ -83,7 +83,7 @@ class NamedtupleMarshalerFactory(MarshalerFactory):
|
|
83
83
|
|
84
84
|
|
85
85
|
class NamedtupleUnmarshalerFactory(UnmarshalerFactory):
|
86
|
-
def make_unmarshaler(self, ctx:
|
86
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
87
87
|
if not _is_namedtuple(rty):
|
88
88
|
return None
|
89
89
|
|
@@ -98,7 +98,7 @@ class NamedtupleUnmarshalerFactory(UnmarshalerFactory):
|
|
98
98
|
defaults: dict[str, ta.Any] = {}
|
99
99
|
|
100
100
|
for fi in fis:
|
101
|
-
tup = (fi, ctx.
|
101
|
+
tup = (fi, ctx.make_unmarshaler(fi.type))
|
102
102
|
|
103
103
|
for un in fi.unmarshal_names:
|
104
104
|
if un in d:
|
@@ -5,6 +5,7 @@ from ... import check
|
|
5
5
|
from ... import dataclasses as dc
|
6
6
|
from ... import reflect as rfl
|
7
7
|
from ..base.contexts import UnmarshalContext
|
8
|
+
from ..base.contexts import UnmarshalFactoryContext
|
8
9
|
from ..base.types import Unmarshaler
|
9
10
|
from ..base.types import UnmarshalerFactory
|
10
11
|
from ..base.values import Value
|
@@ -35,13 +36,13 @@ class ObjectUnmarshaler(Unmarshaler):
|
|
35
36
|
@classmethod
|
36
37
|
def make(
|
37
38
|
cls,
|
38
|
-
ctx:
|
39
|
+
ctx: UnmarshalFactoryContext,
|
39
40
|
factory: ta.Callable,
|
40
41
|
fis: FieldInfos,
|
41
42
|
**kwargs: ta.Any,
|
42
43
|
) -> Unmarshaler:
|
43
44
|
fields_by_unmarshal_name = {
|
44
|
-
n: (fi, ctx.
|
45
|
+
n: (fi, ctx.make_unmarshaler(fi.type))
|
45
46
|
for fi in fis
|
46
47
|
for n in fi.unmarshal_names
|
47
48
|
}
|
@@ -125,7 +126,7 @@ class SimpleObjectUnmarshalerFactory(UnmarshalerFactory):
|
|
125
126
|
|
126
127
|
specials: ObjectSpecials = ObjectSpecials()
|
127
128
|
|
128
|
-
def make_unmarshaler(self, ctx:
|
129
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
129
130
|
if not (isinstance(rty, type) and rty in self.dct):
|
130
131
|
return None
|
131
132
|
|