omlish 0.0.0.dev415__py3-none-any.whl → 0.0.0.dev417__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/bootstrap/__init__.py +2 -2
  3. omlish/dataclasses/__init__.py +28 -14
  4. omlish/dataclasses/impl/processing/base.py +1 -1
  5. omlish/lang/__init__.py +486 -473
  6. omlish/lang/imports/proxyinit.py +161 -48
  7. omlish/lang/maybes.py +8 -0
  8. omlish/marshal/__init__.py +224 -203
  9. omlish/marshal/base/configs.py +18 -0
  10. omlish/marshal/base/contexts.py +23 -19
  11. omlish/marshal/base/overrides.py +26 -12
  12. omlish/marshal/base/registries.py +66 -16
  13. omlish/marshal/base/types.py +60 -8
  14. omlish/marshal/factories/invalidate.py +118 -0
  15. omlish/marshal/factories/moduleimport/__init__.py +0 -0
  16. omlish/marshal/factories/moduleimport/configs.py +26 -0
  17. omlish/marshal/factories/moduleimport/factories.py +114 -0
  18. omlish/marshal/factories/typecache.py +24 -4
  19. omlish/marshal/globals.py +52 -27
  20. omlish/marshal/polymorphism/metadata.py +2 -2
  21. omlish/marshal/standard.py +132 -65
  22. omlish/reflect/__init__.py +57 -47
  23. omlish/reflect/types.py +144 -15
  24. omlish/secrets/all.py +0 -9
  25. omlish/secrets/secrets.py +4 -6
  26. omlish/specs/jsonrpc/__init__.py +2 -2
  27. omlish/specs/jsonschema/__init__.py +2 -2
  28. omlish/specs/openapi/__init__.py +2 -2
  29. omlish/sql/queries/__init__.py +4 -2
  30. omlish/sql/tabledefs/__init__.py +2 -2
  31. omlish/typedvalues/__init__.py +2 -2
  32. {omlish-0.0.0.dev415.dist-info → omlish-0.0.0.dev417.dist-info}/METADATA +14 -9
  33. {omlish-0.0.0.dev415.dist-info → omlish-0.0.0.dev417.dist-info}/RECORD +43 -37
  34. /omlish/bootstrap/{marshal.py → _marshal.py} +0 -0
  35. /omlish/specs/jsonrpc/{marshal.py → _marshal.py} +0 -0
  36. /omlish/specs/jsonschema/{marshal.py → _marshal.py} +0 -0
  37. /omlish/specs/openapi/{marshal.py → _marshal.py} +0 -0
  38. /omlish/sql/queries/{marshal.py → _marshal.py} +0 -0
  39. /omlish/sql/tabledefs/{marshal.py → _marshal.py} +0 -0
  40. {omlish-0.0.0.dev415.dist-info → omlish-0.0.0.dev417.dist-info}/WHEEL +0 -0
  41. {omlish-0.0.0.dev415.dist-info → omlish-0.0.0.dev417.dist-info}/entry_points.txt +0 -0
  42. {omlish-0.0.0.dev415.dist-info → omlish-0.0.0.dev417.dist-info}/licenses/LICENSE +0 -0
  43. {omlish-0.0.0.dev415.dist-info → omlish-0.0.0.dev417.dist-info}/top_level.txt +0 -0
@@ -1,3 +1,4 @@
1
+ # ruff: noqa: I001
1
2
  """
2
3
  TODO:
3
4
  - redacted
@@ -15,211 +16,231 @@ See:
15
16
  - https://github.com/Fatal1ty/mashumaro
16
17
  - https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/serializers.md#custom-serializers
17
18
  """
19
+ from .. import lang as _lang
18
20
 
19
21
 
20
- from .base.contexts import ( # noqa
21
- BaseContext,
22
- MarshalContext,
23
- UnmarshalContext,
24
- )
25
-
26
- from .base.errors import ( # noqa
27
- ForbiddenTypeError,
28
- MarshalError,
29
- UnhandledTypeError,
30
- )
31
-
32
- from .base.options import ( # noqa
33
- Option,
34
- )
35
-
36
- from .base.overrides import ( # noqa
37
- Override,
38
- ReflectOverride,
39
- )
40
-
41
- from .base.registries import ( # noqa
42
- Registry,
43
- )
44
-
45
- from .base.types import ( # noqa
46
- Marshaler,
47
- Unmarshaler,
48
-
49
- MarshalerMaker,
50
- UnmarshalerMaker,
51
-
52
- MarshalerFactory,
53
- UnmarshalerFactory,
54
-
55
- MarshalerFactory_,
56
- UnmarshalerFactory_,
57
- )
58
-
59
- from .base.values import ( # noqa
60
- Value,
61
- )
62
-
63
- from .composite.iterables import ( # noqa
64
- IterableMarshaler,
65
- IterableUnmarshaler,
66
- )
67
-
68
- from .composite.wrapped import ( # noqa
69
- WrappedMarshaler,
70
- WrappedUnmarshaler,
71
- )
72
-
73
- from .factories.simple import ( # noqa
74
- SimpleMarshalerFactory,
75
- SimpleUnmarshalerFactory,
76
- )
77
-
78
- from .factories.match import ( # noqa
79
- MarshalerFactoryMatchClass,
80
- UnmarshalerFactoryMatchClass,
81
- )
82
-
83
- from .factories.multi import ( # noqa
84
- MultiMarshalerFactory,
85
- MultiUnmarshalerFactory,
86
- )
87
-
88
- from .factories.typemap import ( # noqa
89
- TypeMapMarshalerFactory,
90
- TypeMapUnmarshalerFactory,
91
- )
92
-
93
- from .factories.typecache import ( # noqa
94
- TypeCacheMarshalerFactory,
95
- TypeCacheUnmarshalerFactory,
96
- )
97
-
98
- from .factories.func import ( # noqa
99
- FuncMarshaler,
100
- FuncUnmarshaler,
101
- )
102
-
103
- from .factories.recursive import ( # noqa
104
- RecursiveMarshalerFactory,
105
- RecursiveUnmarshalerFactory,
106
- )
107
-
108
- from .objects.dataclasses import ( # noqa
109
- AbstractDataclassFactory,
110
- DataclassMarshalerFactory,
111
- DataclassUnmarshalerFactory,
112
- get_dataclass_field_infos,
113
- get_dataclass_metadata,
114
- )
115
-
116
- from .objects.helpers import ( # noqa
117
- update_fields_metadata,
118
- update_object_metadata,
119
- with_field_metadata,
120
- )
121
-
122
- from .objects.marshal import ( # noqa
123
- ObjectMarshaler,
124
- SimpleObjectMarshalerFactory,
125
- )
126
-
127
- from .objects.metadata import ( # noqa
128
- FieldInfo,
129
- FieldInfos,
130
- FieldMetadata,
131
- FieldOptions,
132
- ObjectMetadata,
133
- ObjectSpecials,
134
- )
135
-
136
- from .objects.unmarshal import ( # noqa
137
- ObjectUnmarshaler,
138
- SimpleObjectUnmarshalerFactory,
139
- )
140
-
141
- from .polymorphism.marshal import ( # noqa
142
- PolymorphismMarshaler,
143
- PolymorphismMarshalerFactory,
144
- make_polymorphism_marshaler,
145
- )
146
-
147
- from .polymorphism.metadata import ( # noqa
148
- FieldTypeTagging,
149
- Impl,
150
- Impls,
151
- Polymorphism,
152
- TypeTagging,
153
- WrapperTypeTagging,
154
- polymorphism_from_impls,
155
- polymorphism_from_subclasses,
156
- )
157
-
158
- from .polymorphism.standard import ( # noqa
159
- standard_polymorphism_factories,
160
- )
161
-
162
- from .polymorphism.unions import ( # noqa
163
- PRIMITIVE_UNION_TYPES,
164
- PolymorphismUnionMarshalerFactory,
165
- PolymorphismUnionUnmarshalerFactory,
166
- PrimitiveUnionMarshaler,
167
- PrimitiveUnionMarshalerFactory,
168
- PrimitiveUnionUnmarshaler,
169
- PrimitiveUnionUnmarshalerFactory,
170
- )
171
-
172
- from .polymorphism.unmarshal import ( # noqa
173
- PolymorphismUnmarshaler,
174
- PolymorphismUnmarshalerFactory,
175
- make_polymorphism_unmarshaler,
176
- )
177
-
178
- from .singular.base64 import ( # noqa
179
- BASE64_MARSHALER_FACTORY,
180
- BASE64_UNMARSHALER_FACTORY,
181
- )
182
-
183
- from .singular.primitives import ( # noqa
184
- PRIMITIVE_TYPES,
185
- )
186
-
187
- from .trivial.forbidden import ( # noqa
188
- ForbiddenTypeMarshalerFactory,
189
- ForbiddenTypeUnmarshalerFactory,
190
- )
191
-
192
- from .trivial.nop import ( # noqa
193
- NOP_MARSHALER_UNMARSHALER,
194
- NopMarshalerUnmarshaler,
195
- )
196
-
197
- from .globals import ( # noqa
198
- GLOBAL_REGISTRY,
199
-
200
- global_marshaler_factory,
201
- marshal,
202
-
203
- global_unmarshaler_factory,
204
- unmarshal,
205
-
206
- register_global,
207
- )
208
-
209
- from .naming import ( # noqa
210
- Naming,
211
- translate_name,
212
- )
213
-
214
- from .standard import ( # noqa
215
- STANDARD_MARSHALER_FACTORIES,
216
- new_standard_marshaler_factory,
217
-
218
- STANDARD_UNMARSHALER_FACTORIES,
219
- new_standard_unmarshaler_factory,
220
-
221
- install_standard_factories,
222
- )
22
+ with _lang.auto_proxy_init(globals()) as _api_cap:
23
+ ##
24
+
25
+ from .base.configs import ( # noqa
26
+ Config,
27
+ ConfigRegistry,
28
+ )
29
+
30
+ from .base.contexts import ( # noqa
31
+ BaseContext,
32
+ MarshalContext,
33
+ UnmarshalContext,
34
+ )
35
+
36
+ from .base.errors import ( # noqa
37
+ ForbiddenTypeError,
38
+ MarshalError,
39
+ UnhandledTypeError,
40
+ )
41
+
42
+ from .base.options import ( # noqa
43
+ Option,
44
+ )
45
+
46
+ from .base.overrides import ( # noqa
47
+ Override,
48
+ ReflectOverride,
49
+ )
50
+
51
+ from .base.registries import ( # noqa
52
+ RegistrySealedError,
53
+ Registry,
54
+ )
55
+
56
+ from .base.types import ( # noqa
57
+ Marshaler,
58
+ Unmarshaler,
59
+
60
+ MarshalerMaker,
61
+ UnmarshalerMaker,
62
+
63
+ MarshalerFactory,
64
+ UnmarshalerFactory,
65
+
66
+ MarshalerFactory_,
67
+ UnmarshalerFactory_,
68
+ )
69
+
70
+ from .base.values import ( # noqa
71
+ Value,
72
+ )
73
+
74
+ from .composite.iterables import ( # noqa
75
+ IterableMarshaler,
76
+ IterableUnmarshaler,
77
+ )
78
+
79
+ from .composite.wrapped import ( # noqa
80
+ WrappedMarshaler,
81
+ WrappedUnmarshaler,
82
+ )
83
+
84
+ from .factories.simple import ( # noqa
85
+ SimpleMarshalerFactory,
86
+ SimpleUnmarshalerFactory,
87
+ )
88
+
89
+ from .factories.match import ( # noqa
90
+ MarshalerFactoryMatchClass,
91
+ UnmarshalerFactoryMatchClass,
92
+ )
93
+
94
+ from .factories.moduleimport.configs import ( # noqa
95
+ ModuleImport,
96
+ )
97
+
98
+ from .factories.moduleimport.factories import ( # noqa
99
+ ModuleImportingMarshalerFactory,
100
+ ModuleImportingUnmarshalerFactory,
101
+ )
102
+
103
+ from .factories.multi import ( # noqa
104
+ MultiMarshalerFactory,
105
+ MultiUnmarshalerFactory,
106
+ )
107
+
108
+ from .factories.typemap import ( # noqa
109
+ TypeMapMarshalerFactory,
110
+ TypeMapUnmarshalerFactory,
111
+ )
112
+
113
+ from .factories.typecache import ( # noqa
114
+ TypeCacheMarshalerFactory,
115
+ TypeCacheUnmarshalerFactory,
116
+ )
117
+
118
+ from .factories.func import ( # noqa
119
+ FuncMarshaler,
120
+ FuncUnmarshaler,
121
+ )
122
+
123
+ from .factories.recursive import ( # noqa
124
+ RecursiveMarshalerFactory,
125
+ RecursiveUnmarshalerFactory,
126
+ )
127
+
128
+ from .objects.dataclasses import ( # noqa
129
+ AbstractDataclassFactory,
130
+ DataclassMarshalerFactory,
131
+ DataclassUnmarshalerFactory,
132
+ get_dataclass_field_infos,
133
+ get_dataclass_metadata,
134
+ )
135
+
136
+ from .objects.helpers import ( # noqa
137
+ update_fields_metadata,
138
+ update_object_metadata,
139
+ with_field_metadata,
140
+ )
141
+
142
+ from .objects.marshal import ( # noqa
143
+ ObjectMarshaler,
144
+ SimpleObjectMarshalerFactory,
145
+ )
146
+
147
+ from .objects.metadata import ( # noqa
148
+ FieldInfo,
149
+ FieldInfos,
150
+ FieldMetadata,
151
+ FieldOptions,
152
+ ObjectMetadata,
153
+ ObjectSpecials,
154
+ )
155
+
156
+ from .objects.unmarshal import ( # noqa
157
+ ObjectUnmarshaler,
158
+ SimpleObjectUnmarshalerFactory,
159
+ )
160
+
161
+ from .polymorphism.marshal import ( # noqa
162
+ PolymorphismMarshaler,
163
+ PolymorphismMarshalerFactory,
164
+ make_polymorphism_marshaler,
165
+ )
166
+
167
+ from .polymorphism.metadata import ( # noqa
168
+ FieldTypeTagging,
169
+ Impl,
170
+ Impls,
171
+ Polymorphism,
172
+ TypeTagging,
173
+ WrapperTypeTagging,
174
+ polymorphism_from_impls,
175
+ polymorphism_from_subclasses,
176
+ )
177
+
178
+ from .polymorphism.standard import ( # noqa
179
+ standard_polymorphism_factories,
180
+ )
181
+
182
+ from .polymorphism.unions import ( # noqa
183
+ PRIMITIVE_UNION_TYPES,
184
+ PolymorphismUnionMarshalerFactory,
185
+ PolymorphismUnionUnmarshalerFactory,
186
+ PrimitiveUnionMarshaler,
187
+ PrimitiveUnionMarshalerFactory,
188
+ PrimitiveUnionUnmarshaler,
189
+ PrimitiveUnionUnmarshalerFactory,
190
+ )
191
+
192
+ from .polymorphism.unmarshal import ( # noqa
193
+ PolymorphismUnmarshaler,
194
+ PolymorphismUnmarshalerFactory,
195
+ make_polymorphism_unmarshaler,
196
+ )
197
+
198
+ from .singular.base64 import ( # noqa
199
+ BASE64_MARSHALER_FACTORY,
200
+ BASE64_UNMARSHALER_FACTORY,
201
+ )
202
+
203
+ from .singular.primitives import ( # noqa
204
+ PRIMITIVE_TYPES,
205
+ )
206
+
207
+ from .trivial.forbidden import ( # noqa
208
+ ForbiddenTypeMarshalerFactory,
209
+ ForbiddenTypeUnmarshalerFactory,
210
+ )
211
+
212
+ from .trivial.nop import ( # noqa
213
+ NOP_MARSHALER_UNMARSHALER,
214
+ NopMarshalerUnmarshaler,
215
+ )
216
+
217
+ from .globals import ( # noqa
218
+ global_config_registry,
219
+ global_marshaler_factory,
220
+ global_unmarshaler_factory,
221
+ global_marshaling,
222
+
223
+ marshal,
224
+ unmarshal,
225
+
226
+ register_global_config,
227
+ register_global_module_import,
228
+ )
229
+
230
+ from .naming import ( # noqa
231
+ Naming,
232
+ translate_name,
233
+ )
234
+
235
+ from .standard import ( # noqa
236
+ StandardFactories,
237
+ DEFAULT_STANDARD_FACTORIES,
238
+
239
+ new_standard_marshaler_factory,
240
+ new_standard_unmarshaler_factory,
241
+
242
+ install_standard_factories,
243
+ )
223
244
 
224
245
 
225
246
  ##
@@ -0,0 +1,18 @@
1
+ import typing as ta
2
+
3
+ from ... import lang
4
+ from .registries import Registry
5
+ from .registries import RegistryItem
6
+
7
+
8
+ ##
9
+
10
+
11
+ class Config(RegistryItem, lang.Abstract):
12
+ pass
13
+
14
+
15
+ ConfigRegistry: ta.TypeAlias = Registry[Config]
16
+
17
+
18
+ EMPTY_CONFIG_REGISTRY = ConfigRegistry().seal()
@@ -1,20 +1,24 @@
1
+ import dataclasses as dc
1
2
  import typing as ta
2
3
 
3
4
  from ... import check
4
5
  from ... import collections as col
5
- from ... import dataclasses as dc
6
6
  from ... import lang
7
7
  from ... import reflect as rfl
8
8
  from ...funcs import match as mfs
9
+ from .configs import EMPTY_CONFIG_REGISTRY
10
+ from .configs import ConfigRegistry
9
11
  from .errors import UnhandledTypeError
10
12
  from .options import Option
11
13
  from .overrides import ReflectOverride
12
- from .registries import Registry
13
- from .types import Marshaler
14
- from .types import MarshalerFactory
15
- from .types import Unmarshaler
16
- from .types import UnmarshalerFactory
17
- from .values import Value
14
+
15
+
16
+ if ta.TYPE_CHECKING:
17
+ from .types import Marshaler
18
+ from .types import MarshalerFactory
19
+ from .types import Unmarshaler
20
+ from .types import UnmarshalerFactory
21
+ from .values import Value
18
22
 
19
23
 
20
24
  T = ta.TypeVar('T')
@@ -23,40 +27,40 @@ T = ta.TypeVar('T')
23
27
  ##
24
28
 
25
29
 
26
- @dc.dataclass(frozen=True)
30
+ @dc.dataclass(frozen=True, kw_only=True)
27
31
  class BaseContext(lang.Abstract):
28
- registry: Registry
32
+ config_registry: ConfigRegistry = EMPTY_CONFIG_REGISTRY
29
33
  options: col.TypeMap[Option] = col.TypeMap()
30
34
 
31
35
  def _reflect(self, o: ta.Any) -> rfl.Type:
32
36
  def override(o):
33
- if (ovr := self.registry.get_of(o, ReflectOverride)):
37
+ if (ovr := self.config_registry.get_of(o, ReflectOverride)):
34
38
  return ovr[-1].rty
35
39
  return None
36
40
 
37
41
  return rfl.Reflector(override=override).type(o)
38
42
 
39
43
 
40
- @dc.dataclass(frozen=True)
44
+ @dc.dataclass(frozen=True, kw_only=True)
41
45
  class MarshalContext(BaseContext, lang.Final):
42
- factory: MarshalerFactory | None = None
46
+ factory: ta.Optional['MarshalerFactory'] = None
43
47
 
44
- def make(self, o: ta.Any) -> Marshaler:
48
+ def make(self, o: ta.Any) -> 'Marshaler':
45
49
  rty = self._reflect(o)
46
50
  try:
47
51
  return check.not_none(self.factory).make_marshaler(self, rty)
48
52
  except mfs.MatchGuardError:
49
53
  raise UnhandledTypeError(rty) # noqa
50
54
 
51
- def marshal(self, obj: ta.Any, ty: ta.Any | None = None) -> Value:
55
+ def marshal(self, obj: ta.Any, ty: ta.Any | None = None) -> 'Value':
52
56
  return self.make(ty if ty is not None else type(obj)).marshal(self, obj)
53
57
 
54
58
 
55
- @dc.dataclass(frozen=True)
59
+ @dc.dataclass(frozen=True, kw_only=True)
56
60
  class UnmarshalContext(BaseContext, lang.Final):
57
- factory: UnmarshalerFactory | None = None
61
+ factory: ta.Optional['UnmarshalerFactory'] = None
58
62
 
59
- def make(self, o: ta.Any) -> Unmarshaler:
63
+ def make(self, o: ta.Any) -> 'Unmarshaler':
60
64
  rty = self._reflect(o)
61
65
  try:
62
66
  return check.not_none(self.factory).make_unmarshaler(self, rty)
@@ -64,11 +68,11 @@ class UnmarshalContext(BaseContext, lang.Final):
64
68
  raise UnhandledTypeError(rty) # noqa
65
69
 
66
70
  @ta.overload
67
- def unmarshal(self, v: Value, ty: type[T]) -> T:
71
+ def unmarshal(self, v: 'Value', ty: type[T]) -> T:
68
72
  ...
69
73
 
70
74
  @ta.overload
71
- def unmarshal(self, v: Value, ty: ta.Any) -> ta.Any:
75
+ def unmarshal(self, v: 'Value', ty: ta.Any) -> ta.Any:
72
76
  ...
73
77
 
74
78
  def unmarshal(self, v, ty):
@@ -1,25 +1,39 @@
1
- from ... import dataclasses as dc
1
+ import dataclasses as dc
2
+ import typing as ta
3
+
4
+ from ... import check
2
5
  from ... import lang
3
6
  from ... import reflect as rfl
4
- from .registries import RegistryItem
5
- from .types import Marshaler
6
- from .types import MarshalerFactory
7
- from .types import Unmarshaler
8
- from .types import UnmarshalerFactory
7
+ from .configs import Config
8
+
9
+
10
+ if ta.TYPE_CHECKING:
11
+ from . import types as _types
12
+ from .types import Marshaler
13
+ from .types import MarshalerFactory
14
+ from .types import Unmarshaler
15
+ from .types import UnmarshalerFactory
16
+
17
+ else:
18
+ _types = lang.proxy_import('.types', __package__)
9
19
 
10
20
 
11
21
  ##
12
22
 
13
23
 
14
24
  @dc.dataclass(frozen=True, kw_only=True)
15
- class Override(RegistryItem, lang.Final):
16
- marshaler: Marshaler | None = dc.xfield(None, check_type=(Marshaler, None))
17
- marshaler_factory: MarshalerFactory | None = None
25
+ class Override(Config, lang.Final):
26
+ marshaler: ta.Optional['Marshaler'] = None
27
+ marshaler_factory: ta.Optional['MarshalerFactory'] = None
28
+
29
+ unmarshaler: ta.Optional['Unmarshaler'] = None
30
+ unmarshaler_factory: ta.Optional['UnmarshalerFactory'] = None
18
31
 
19
- unmarshaler: Unmarshaler | None = dc.xfield(None, check_type=(Unmarshaler, None))
20
- unmarshaler_factory: UnmarshalerFactory | None = None
32
+ def __post_init__(self) -> None:
33
+ check.isinstance(self.marshaler, (_types.Marshaler, None))
34
+ check.isinstance(self.unmarshaler, (_types.Unmarshaler, None))
21
35
 
22
36
 
23
37
  @dc.dataclass(frozen=True)
24
- class ReflectOverride(RegistryItem, lang.Final):
38
+ class ReflectOverride(Config, lang.Final):
25
39
  rty: rfl.Type