omlish 0.0.0.dev454__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.
Files changed (43) hide show
  1. omlish/__about__.py +2 -2
  2. omlish/lang/functions.py +2 -2
  3. omlish/marshal/__init__.py +4 -0
  4. omlish/marshal/base/contexts.py +29 -13
  5. omlish/marshal/base/funcs.py +4 -12
  6. omlish/marshal/base/options.py +8 -0
  7. omlish/marshal/base/types.py +25 -11
  8. omlish/marshal/composite/iterables.py +10 -8
  9. omlish/marshal/composite/literals.py +6 -4
  10. omlish/marshal/composite/mappings.py +10 -8
  11. omlish/marshal/composite/maybes.py +10 -8
  12. omlish/marshal/composite/newtypes.py +6 -6
  13. omlish/marshal/composite/optionals.py +6 -4
  14. omlish/marshal/composite/special.py +6 -6
  15. omlish/marshal/composite/unions/literals.py +6 -4
  16. omlish/marshal/composite/unions/primitives.py +6 -4
  17. omlish/marshal/factories/invalidate.py +4 -4
  18. omlish/marshal/factories/method.py +4 -6
  19. omlish/marshal/factories/moduleimport/factories.py +4 -4
  20. omlish/marshal/factories/multi.py +4 -4
  21. omlish/marshal/factories/recursive.py +4 -2
  22. omlish/marshal/factories/typecache.py +4 -9
  23. omlish/marshal/factories/typemap.py +4 -4
  24. omlish/marshal/objects/dataclasses.py +30 -16
  25. omlish/marshal/objects/marshal.py +4 -3
  26. omlish/marshal/objects/namedtuples.py +6 -6
  27. omlish/marshal/objects/unmarshal.py +4 -3
  28. omlish/marshal/polymorphism/marshal.py +4 -3
  29. omlish/marshal/polymorphism/unions.py +7 -7
  30. omlish/marshal/polymorphism/unmarshal.py +4 -3
  31. omlish/marshal/singular/enums.py +4 -2
  32. omlish/marshal/trivial/any.py +1 -1
  33. omlish/marshal/trivial/forbidden.py +4 -4
  34. omlish/specs/jsonrpc/_marshal.py +4 -4
  35. omlish/specs/openapi/_marshal.py +16 -10
  36. omlish/typedvalues/marshal.py +14 -14
  37. {omlish-0.0.0.dev454.dist-info → omlish-0.0.0.dev455.dist-info}/METADATA +1 -1
  38. {omlish-0.0.0.dev454.dist-info → omlish-0.0.0.dev455.dist-info}/RECORD +42 -43
  39. omlish/funcs/match.py +0 -229
  40. {omlish-0.0.0.dev454.dist-info → omlish-0.0.0.dev455.dist-info}/WHEEL +0 -0
  41. {omlish-0.0.0.dev454.dist-info → omlish-0.0.0.dev455.dist-info}/entry_points.txt +0 -0
  42. {omlish-0.0.0.dev454.dist-info → omlish-0.0.0.dev455.dist-info}/licenses/LICENSE +0 -0
  43. {omlish-0.0.0.dev454.dist-info → omlish-0.0.0.dev455.dist-info}/top_level.txt +0 -0
omlish/__about__.py CHANGED
@@ -1,5 +1,5 @@
1
- __version__ = '0.0.0.dev454'
2
- __revision__ = '59a1efb9c2d924f74345aa315eef7c197a2d3a91'
1
+ __version__ = '0.0.0.dev455'
2
+ __revision__ = '83eb94a310c0880350d3f2b4440d1673f4d9402d'
3
3
 
4
4
 
5
5
  #
omlish/lang/functions.py CHANGED
@@ -59,11 +59,11 @@ def recurse(fn: ta.Callable[..., T], *args, **kwargs) -> T:
59
59
  ##
60
60
 
61
61
 
62
- def raise_(o: BaseException) -> ta.NoReturn:
62
+ def raise_(o: BaseException | type[BaseException]) -> ta.NoReturn:
63
63
  raise o
64
64
 
65
65
 
66
- def raising(o: BaseException) -> ta.Callable[..., ta.NoReturn]:
66
+ def raising(o: BaseException | type[BaseException]) -> ta.Callable[..., ta.NoReturn]:
67
67
  def inner(*args, **kwargs):
68
68
  raise o
69
69
 
@@ -54,6 +54,10 @@ with _lang.auto_proxy_init(globals()):
54
54
 
55
55
  from .base.contexts import ( # noqa
56
56
  BaseContext,
57
+
58
+ MarshalFactoryContext,
59
+ UnmarshalFactoryContext,
60
+
57
61
  MarshalContext,
58
62
  UnmarshalContext,
59
63
  )
@@ -27,7 +27,7 @@ T = ta.TypeVar('T')
27
27
 
28
28
 
29
29
  @dc.dataclass(frozen=True, kw_only=True)
30
- class BaseContext(lang.Abstract):
30
+ class BaseContext(lang.Abstract, lang.Sealed):
31
31
  config_registry: ConfigRegistry = EMPTY_CONFIG_REGISTRY
32
32
  options: col.TypeMap[Option] = col.TypeMap()
33
33
 
@@ -40,32 +40,48 @@ class BaseContext(lang.Abstract):
40
40
  return rfl.Reflector(override=override).type(o)
41
41
 
42
42
 
43
+ #
44
+
45
+
43
46
  @dc.dataclass(frozen=True, kw_only=True)
44
- class MarshalContext(BaseContext, lang.Final):
45
- factory: ta.Optional['MarshalerFactory'] = None
47
+ class MarshalFactoryContext(BaseContext, lang.Final):
48
+ marshaler_factory: ta.Optional['MarshalerFactory'] = None
46
49
 
47
- def make(self, o: ta.Any) -> 'Marshaler':
50
+ def make_marshaler(self, o: ta.Any) -> 'Marshaler':
48
51
  rty = self._reflect(o)
49
- fac = check.not_none(self.factory)
52
+ fac = check.not_none(self.marshaler_factory)
50
53
  if (mfn := fac.make_marshaler(self, rty)) is None:
51
54
  raise UnhandledTypeError(rty) # noqa
52
55
  return mfn()
53
56
 
54
- def marshal(self, obj: ta.Any, ty: ta.Any | None = None) -> 'Value':
55
- return self.make(ty if ty is not None else type(obj)).marshal(self, obj)
56
-
57
57
 
58
58
  @dc.dataclass(frozen=True, kw_only=True)
59
- class UnmarshalContext(BaseContext, lang.Final):
60
- factory: ta.Optional['UnmarshalerFactory'] = None
59
+ class UnmarshalFactoryContext(BaseContext, lang.Final):
60
+ unmarshaler_factory: ta.Optional['UnmarshalerFactory'] = None
61
61
 
62
- def make(self, o: ta.Any) -> 'Unmarshaler':
62
+ def make_unmarshaler(self, o: ta.Any) -> 'Unmarshaler':
63
63
  rty = self._reflect(o)
64
- fac = check.not_none(self.factory)
64
+ fac = check.not_none(self.unmarshaler_factory)
65
65
  if (mfn := fac.make_unmarshaler(self, rty)) is None:
66
66
  raise UnhandledTypeError(rty) # noqa
67
67
  return mfn()
68
68
 
69
+
70
+ #
71
+
72
+
73
+ @dc.dataclass(frozen=True, kw_only=True)
74
+ class MarshalContext(BaseContext, lang.Final):
75
+ marshal_factory_context: MarshalFactoryContext
76
+
77
+ def marshal(self, obj: ta.Any, ty: ta.Any | None = None) -> 'Value':
78
+ return self.marshal_factory_context.make_marshaler(ty if ty is not None else type(obj)).marshal(self, obj)
79
+
80
+
81
+ @dc.dataclass(frozen=True, kw_only=True)
82
+ class UnmarshalContext(BaseContext, lang.Final):
83
+ unmarshal_factory_context: UnmarshalFactoryContext
84
+
69
85
  @ta.overload
70
86
  def unmarshal(self, v: 'Value', ty: type[T]) -> T:
71
87
  ...
@@ -75,4 +91,4 @@ class UnmarshalContext(BaseContext, lang.Final):
75
91
  ...
76
92
 
77
93
  def unmarshal(self, v, ty):
78
- return self.make(ty).unmarshal(self, v)
94
+ return self.unmarshal_factory_context.make_unmarshaler(ty).unmarshal(self, v)
@@ -3,9 +3,10 @@ import typing as ta
3
3
 
4
4
  from ... import lang
5
5
  from ... import reflect as rfl
6
- from ...funcs import guard as gfs
7
6
  from .contexts import MarshalContext
7
+ from .contexts import MarshalFactoryContext
8
8
  from .contexts import UnmarshalContext
9
+ from .contexts import UnmarshalFactoryContext
9
10
  from .types import Marshaler
10
11
  from .types import MarshalerFactory
11
12
  from .types import MarshalerMaker
@@ -41,7 +42,7 @@ class FuncUnmarshaler(Unmarshaler, lang.Final):
41
42
  class FuncMarshalerFactory(MarshalerFactory): # noqa
42
43
  gf: MarshalerMaker
43
44
 
44
- def make_marshaler(self, ctx: MarshalContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
45
+ def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
45
46
  return self.gf(ctx, rty)
46
47
 
47
48
 
@@ -49,14 +50,5 @@ class FuncMarshalerFactory(MarshalerFactory): # noqa
49
50
  class FuncUnmarshalerFactory(UnmarshalerFactory): # noqa
50
51
  gf: UnmarshalerMaker
51
52
 
52
- def make_unmarshaler(self, ctx: UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
53
+ def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
53
54
  return self.gf(ctx, rty)
54
-
55
-
56
- ##
57
-
58
-
59
- class GuardMethodMarshalerFactory(MarshalerFactory):
60
- @gfs.method(instance_cache=True)
61
- def make_marshaler(self, ctx: MarshalContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
62
- raise NotImplementedError
@@ -1,2 +1,10 @@
1
+ """
2
+ TODO:
3
+ - MarshalOption, UnmarshalOption, check if a context got something unexpected
4
+ - Options only apply to Factories?
5
+ - MarshalFactoryOption, MarshalOption, UnmarshalFactoryOption, MarshalOption ?
6
+ """
7
+
8
+
1
9
  class Option:
2
10
  pass
@@ -6,7 +6,9 @@ from ... import reflect as rfl
6
6
  from ...funcs import guard as gfs
7
7
  from .configs import ConfigRegistry
8
8
  from .contexts import MarshalContext
9
+ from .contexts import MarshalFactoryContext
9
10
  from .contexts import UnmarshalContext
11
+ from .contexts import UnmarshalFactoryContext
10
12
  from .values import Value
11
13
 
12
14
 
@@ -31,19 +33,19 @@ class Unmarshaler(lang.Abstract):
31
33
  ##
32
34
 
33
35
 
34
- MarshalerMaker: ta.TypeAlias = gfs.GuardFn[[MarshalContext, rfl.Type], Marshaler]
35
- UnmarshalerMaker: ta.TypeAlias = gfs.GuardFn[[UnmarshalContext, rfl.Type], Unmarshaler]
36
+ MarshalerMaker: ta.TypeAlias = gfs.GuardFn[[MarshalFactoryContext, rfl.Type], Marshaler]
37
+ UnmarshalerMaker: ta.TypeAlias = gfs.GuardFn[[UnmarshalFactoryContext, rfl.Type], Unmarshaler]
36
38
 
37
39
 
38
40
  class MarshalerFactory(lang.Abstract):
39
41
  @abc.abstractmethod
40
- def make_marshaler(self, ctx: MarshalContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
42
+ def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
41
43
  raise NotImplementedError
42
44
 
43
45
 
44
46
  class UnmarshalerFactory(lang.Abstract):
45
47
  @abc.abstractmethod
46
- def make_unmarshaler(self, ctx: UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
48
+ def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
47
49
  raise NotImplementedError
48
50
 
49
51
 
@@ -63,20 +65,32 @@ class Marshaling(lang.Abstract):
63
65
  def unmarshaler_factory(self) -> UnmarshalerFactory:
64
66
  raise NotImplementedError
65
67
 
66
- #
68
+ ##
69
+
70
+ def new_marshal_factory_context(self) -> MarshalFactoryContext:
71
+ return MarshalFactoryContext(
72
+ config_registry=self.config_registry(),
73
+ marshaler_factory=self.marshaler_factory(),
74
+ )
75
+
76
+ def new_unmarshal_factory_context(self) -> UnmarshalFactoryContext:
77
+ return UnmarshalFactoryContext(
78
+ config_registry=self.config_registry(),
79
+ unmarshaler_factory=self.unmarshaler_factory(),
80
+ )
81
+
82
+ ##
67
83
 
68
- def new_marshal_context(self, **kwargs: ta.Any) -> MarshalContext:
84
+ def new_marshal_context(self) -> MarshalContext:
69
85
  return MarshalContext(
70
86
  config_registry=self.config_registry(),
71
- factory=self.marshaler_factory(),
72
- **kwargs,
87
+ marshal_factory_context=self.new_marshal_factory_context(),
73
88
  )
74
89
 
75
- def new_unmarshal_context(self, **kwargs: ta.Any) -> UnmarshalContext:
90
+ def new_unmarshal_context(self) -> UnmarshalContext:
76
91
  return UnmarshalContext(
77
92
  config_registry=self.config_registry(),
78
- factory=self.unmarshaler_factory(),
79
- **kwargs,
93
+ unmarshal_factory_context=self.new_unmarshal_factory_context(),
80
94
  )
81
95
 
82
96
  #
@@ -10,7 +10,9 @@ import typing as ta
10
10
  from ... import check
11
11
  from ... import reflect as rfl
12
12
  from ..base.contexts import MarshalContext
13
+ from ..base.contexts import MarshalFactoryContext
13
14
  from ..base.contexts import UnmarshalContext
15
+ from ..base.contexts import UnmarshalFactoryContext
14
16
  from ..base.types import Marshaler
15
17
  from ..base.types import Unmarshaler
16
18
  from ..base.values import Value
@@ -41,16 +43,16 @@ class IterableMarshaler(Marshaler):
41
43
 
42
44
  class IterableMarshalerFactory(MarshalerFactoryMethodClass):
43
45
  @MarshalerFactoryMethodClass.make_marshaler.register
44
- def _make_generic(self, ctx: MarshalContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
46
+ def _make_generic(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
45
47
  if not (isinstance(rty, rfl.Generic) and issubclass(rty.cls, collections.abc.Iterable)):
46
48
  return None
47
- return lambda: IterableMarshaler(ctx.make(check.single(rty.args)))
49
+ return lambda: IterableMarshaler(ctx.make_marshaler(check.single(rty.args)))
48
50
 
49
51
  @MarshalerFactoryMethodClass.make_marshaler.register
50
- def _make_concrete(self, ctx: MarshalContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
52
+ def _make_concrete(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
51
53
  if not (isinstance(rty, type) and issubclass(rty, collections.abc.Iterable)):
52
54
  return None
53
- return lambda: IterableMarshaler(ctx.make(ta.Any))
55
+ return lambda: IterableMarshaler(ctx.make_marshaler(ta.Any))
54
56
 
55
57
 
56
58
  #
@@ -67,14 +69,14 @@ class IterableUnmarshaler(Unmarshaler):
67
69
 
68
70
  class IterableUnmarshalerFactory(UnmarshalerFactoryMethodClass):
69
71
  @UnmarshalerFactoryMethodClass.make_unmarshaler.register
70
- def _make_generic(self, ctx: UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
72
+ def _make_generic(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
71
73
  if not (isinstance(rty, rfl.Generic) and issubclass(rty.cls, collections.abc.Iterable)):
72
74
  return None
73
75
  cty = DEFAULT_ITERABLE_CONCRETE_TYPES.get(rty.cls, rty.cls) # noqa
74
- return lambda: IterableUnmarshaler(cty, ctx.make(check.single(rty.args))) # noqa
76
+ return lambda: IterableUnmarshaler(cty, ctx.make_unmarshaler(check.single(rty.args))) # noqa
75
77
 
76
78
  @UnmarshalerFactoryMethodClass.make_unmarshaler.register
77
- def _make_concrete(self, ctx: UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
79
+ def _make_concrete(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
78
80
  if not (isinstance(rty, type) and issubclass(rty, collections.abc.Iterable)):
79
81
  return None
80
- return lambda: IterableUnmarshaler(check.isinstance(rty, type), ctx.make(ta.Any))
82
+ return lambda: IterableUnmarshaler(check.isinstance(rty, type), ctx.make_unmarshaler(ta.Any))
@@ -8,7 +8,9 @@ import typing as ta
8
8
  from ... import check
9
9
  from ... import reflect as rfl
10
10
  from ..base.contexts import MarshalContext
11
+ from ..base.contexts import MarshalFactoryContext
11
12
  from ..base.contexts import UnmarshalContext
13
+ from ..base.contexts import UnmarshalFactoryContext
12
14
  from ..base.types import Marshaler
13
15
  from ..base.types import MarshalerFactory
14
16
  from ..base.types import Unmarshaler
@@ -29,11 +31,11 @@ class LiteralMarshaler(Marshaler):
29
31
 
30
32
 
31
33
  class LiteralMarshalerFactory(MarshalerFactory):
32
- def make_marshaler(self, ctx: MarshalContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
34
+ def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
33
35
  if not (isinstance(rty, rfl.Literal) and len(set(map(type, rty.args))) == 1):
34
36
  return None
35
37
  ety = check.single(set(map(type, rty.args)))
36
- return lambda: LiteralMarshaler(ctx.make(ety), frozenset(rty.args))
38
+ return lambda: LiteralMarshaler(ctx.make_marshaler(ety), frozenset(rty.args))
37
39
 
38
40
 
39
41
  @dc.dataclass(frozen=True)
@@ -46,8 +48,8 @@ class LiteralUnmarshaler(Unmarshaler):
46
48
 
47
49
 
48
50
  class LiteralUnmarshalerFactory(UnmarshalerFactory):
49
- def make_unmarshaler(self, ctx: UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
51
+ def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
50
52
  if not (isinstance(rty, rfl.Literal) and len(set(map(type, rty.args))) == 1):
51
53
  return None
52
54
  ety = check.single(set(map(type, rty.args)))
53
- return lambda: LiteralUnmarshaler(ctx.make(ety), frozenset(rty.args))
55
+ return lambda: LiteralUnmarshaler(ctx.make_unmarshaler(ety), frozenset(rty.args))
@@ -5,7 +5,9 @@ import typing as ta
5
5
  from ... import check
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 Unmarshaler
11
13
  from ..base.values import Value
@@ -39,17 +41,17 @@ class MappingMarshaler(Marshaler):
39
41
 
40
42
  class MappingMarshalerFactory(MarshalerFactoryMethodClass):
41
43
  @MarshalerFactoryMethodClass.make_marshaler.register
42
- def _build_generic(self, ctx: MarshalContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
44
+ def _make_generic(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
43
45
  if not (isinstance(rty, rfl.Generic) and issubclass(rty.cls, collections.abc.Mapping)):
44
46
  return None
45
47
  kt, vt = rty.args
46
- return lambda: MappingMarshaler(ctx.make(kt), ctx.make(vt))
48
+ return lambda: MappingMarshaler(ctx.make_marshaler(kt), ctx.make_marshaler(vt))
47
49
 
48
50
  @MarshalerFactoryMethodClass.make_marshaler.register
49
- def _build_concrete(self, ctx: MarshalContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
51
+ def _make_concrete(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
50
52
  if not (isinstance(rty, type) and issubclass(rty, collections.abc.Mapping)):
51
53
  return None
52
- return lambda: MappingMarshaler(a := ctx.make(ta.Any), a)
54
+ return lambda: MappingMarshaler(a := ctx.make_marshaler(ta.Any), a)
53
55
 
54
56
 
55
57
  #
@@ -70,15 +72,15 @@ class MappingUnmarshaler(Unmarshaler):
70
72
 
71
73
  class MappingUnmarshalerFactory(UnmarshalerFactoryMethodClass):
72
74
  @UnmarshalerFactoryMethodClass.make_unmarshaler.register
73
- def _build_generic(self, ctx: UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
75
+ def _make_generic(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
74
76
  if not (isinstance(rty, rfl.Generic) and issubclass(rty.cls, collections.abc.Mapping)):
75
77
  return None
76
78
  cty = DEFAULT_MAPPING_CONCRETE_TYPES.get(rty.cls, rty.cls) # noqa
77
79
  kt, vt = rty.args
78
- return lambda: MappingUnmarshaler(cty, ctx.make(kt), ctx.make(vt))
80
+ return lambda: MappingUnmarshaler(cty, ctx.make_unmarshaler(kt), ctx.make_unmarshaler(vt))
79
81
 
80
82
  @UnmarshalerFactoryMethodClass.make_unmarshaler.register
81
- def _build_concrete(self, ctx: UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
83
+ def _make_concrete(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
82
84
  if not (isinstance(rty, type) and issubclass(rty, collections.abc.Mapping)):
83
85
  return None
84
- return lambda: MappingUnmarshaler(check.isinstance(rty, type), a := ctx.make(ta.Any), a)
86
+ return lambda: MappingUnmarshaler(check.isinstance(rty, type), a := ctx.make_unmarshaler(ta.Any), a)
@@ -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: MarshalContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
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.make(check.single(rty.args)))
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: MarshalContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
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.make(ta.Any))
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: UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
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.make(check.single(rty.args)))
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: UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
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.make(ta.Any))
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 MarshalContext
6
- from ..base.contexts import UnmarshalContext
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: MarshalContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
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.make(check.isinstance(rty, rfl.NewType).ty)
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: UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
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.make(check.isinstance(rty, rfl.NewType).ty)
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: MarshalContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
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.make(check.isinstance(rty, rfl.Union).without_none()))
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: UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
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.make(check.isinstance(rty, rfl.Union).without_none()))
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 MarshalContext
8
- from ..base.contexts import UnmarshalContext
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: MarshalContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
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.make(check.single(rty.args)))
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: UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
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.make(check.single(rty.args)))
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: MarshalContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
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.make(ds.lit), ctx.make(ds.non_lit))
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: UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
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.make(ds.lit), ctx.make(ds.non_lit))
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: MarshalContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
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.make(check.single(ds.non_prim)) if ds.non_prim else None,
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: UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
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.make(check.single(ds.non_prim)) if ds.non_prim else None,
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 MarshalContext
6
- from ..base.contexts import UnmarshalContext
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: MarshalContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
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: UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
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 MarshalContext
7
- from ..base.contexts import UnmarshalContext
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: MarshalContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
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: UnmarshalContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
25
+ def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
28
26
  raise NotImplementedError