omlish 0.0.0.dev414__py3-none-any.whl → 0.0.0.dev415__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 (65) hide show
  1. omlish/__about__.py +2 -3
  2. omlish/codecs/registry.py +1 -1
  3. omlish/dataclasses/__init__.py +135 -113
  4. omlish/dataclasses/impl/api/classes/make.py +5 -3
  5. omlish/dataclasses/impl/configs.py +29 -29
  6. omlish/lite/maysyncs.py +1 -0
  7. omlish/manifests/base.py +1 -1
  8. omlish/marshal/__init__.py +98 -57
  9. omlish/marshal/base/__init__.py +0 -0
  10. omlish/marshal/base/contexts.py +75 -0
  11. omlish/marshal/{errors.py → base/errors.py} +1 -1
  12. omlish/marshal/base/options.py +2 -0
  13. omlish/marshal/base/overrides.py +25 -0
  14. omlish/marshal/{registries.py → base/registries.py} +4 -8
  15. omlish/marshal/base/types.py +70 -0
  16. omlish/marshal/{values.py → base/values.py} +1 -13
  17. omlish/marshal/composite/iterables.py +7 -7
  18. omlish/marshal/composite/literals.py +7 -7
  19. omlish/marshal/composite/mappings.py +7 -7
  20. omlish/marshal/composite/maybes.py +7 -7
  21. omlish/marshal/composite/newtypes.py +6 -6
  22. omlish/marshal/composite/optionals.py +7 -7
  23. omlish/marshal/composite/special.py +6 -6
  24. omlish/marshal/composite/wrapped.py +5 -5
  25. omlish/marshal/factories/__init__.py +0 -0
  26. omlish/marshal/factories/func.py +28 -0
  27. omlish/marshal/factories/match.py +34 -0
  28. omlish/marshal/factories/multi.py +55 -0
  29. omlish/marshal/factories/recursive.py +120 -0
  30. omlish/marshal/factories/simple.py +28 -0
  31. omlish/marshal/factories/typecache.py +91 -0
  32. omlish/marshal/factories/typemap.py +65 -0
  33. omlish/marshal/globals.py +7 -7
  34. omlish/marshal/naming.py +1 -1
  35. omlish/marshal/objects/dataclasses.py +7 -7
  36. omlish/marshal/objects/marshal.py +4 -4
  37. omlish/marshal/objects/metadata.py +4 -4
  38. omlish/marshal/objects/namedtuples.py +7 -7
  39. omlish/marshal/objects/unmarshal.py +4 -4
  40. omlish/marshal/polymorphism/marshal.py +4 -4
  41. omlish/marshal/polymorphism/metadata.py +1 -1
  42. omlish/marshal/polymorphism/standard.py +2 -2
  43. omlish/marshal/polymorphism/unions.py +7 -7
  44. omlish/marshal/polymorphism/unmarshal.py +4 -4
  45. omlish/marshal/singular/base64.py +7 -7
  46. omlish/marshal/singular/datetimes.py +7 -7
  47. omlish/marshal/singular/enums.py +7 -7
  48. omlish/marshal/singular/numbers.py +7 -7
  49. omlish/marshal/singular/primitives.py +7 -7
  50. omlish/marshal/singular/uuids.py +7 -7
  51. omlish/marshal/standard.py +8 -8
  52. omlish/marshal/trivial/any.py +7 -7
  53. omlish/marshal/trivial/forbidden.py +7 -7
  54. omlish/marshal/trivial/nop.py +5 -5
  55. {omlish-0.0.0.dev414.dist-info → omlish-0.0.0.dev415.dist-info}/METADATA +1 -1
  56. {omlish-0.0.0.dev414.dist-info → omlish-0.0.0.dev415.dist-info}/RECORD +60 -52
  57. omlish/inject/.dataclasses.json +0 -3
  58. omlish/marshal/.dataclasses.json +0 -3
  59. omlish/marshal/base.py +0 -472
  60. omlish/marshal/factories.py +0 -116
  61. omlish/marshal/proxy.py +0 -26
  62. {omlish-0.0.0.dev414.dist-info → omlish-0.0.0.dev415.dist-info}/WHEEL +0 -0
  63. {omlish-0.0.0.dev414.dist-info → omlish-0.0.0.dev415.dist-info}/entry_points.txt +0 -0
  64. {omlish-0.0.0.dev414.dist-info → omlish-0.0.0.dev415.dist-info}/licenses/LICENSE +0 -0
  65. {omlish-0.0.0.dev414.dist-info → omlish-0.0.0.dev415.dist-info}/top_level.txt +0 -0
omlish/__about__.py CHANGED
@@ -1,5 +1,5 @@
1
- __version__ = '0.0.0.dev414'
2
- __revision__ = '4d74fcb86928f83d6b52b2e24206bc833ee18f1e'
1
+ __version__ = '0.0.0.dev415'
2
+ __revision__ = '79bb2b1f7af2d9c344f8471cd6e785914768a72f'
3
3
 
4
4
 
5
5
  #
@@ -175,7 +175,6 @@ class SetuptoolsBase:
175
175
  '*.g4',
176
176
  '*.h',
177
177
 
178
- '.dataclasses.json',
179
178
  '.manifests.json',
180
179
 
181
180
  'LICENSE',
omlish/codecs/registry.py CHANGED
@@ -77,7 +77,7 @@ class CodecRegistry:
77
77
  codec_or_lazy = self._by_name[name]
78
78
 
79
79
  if isinstance(codec_or_lazy, LazyLoadedCodec):
80
- codec = check.isinstance(codec_or_lazy.load(), Codec)
80
+ codec = check.isinstance(codec_or_lazy.resolve(), Codec)
81
81
  self._by_name[name] = codec
82
82
  self._post_load(codec)
83
83
  else:
@@ -1,158 +1,180 @@
1
- ##
2
- # stdlib interface
1
+ # ruff: noqa: I001
2
+ import sys as _sys
3
3
 
4
- from dataclasses import ( # noqa
5
- FrozenInstanceError,
4
+ from .. import lang as _lang
6
5
 
7
- MISSING,
8
- KW_ONLY,
9
6
 
10
- InitVar,
11
- Field,
7
+ with _lang.auto_proxy_init(globals()):
8
+ ##
12
9
 
13
- field,
10
+ ##
11
+ # stdlib interface
14
12
 
15
- dataclass,
16
- make_dataclass,
13
+ from dataclasses import ( # noqa
14
+ FrozenInstanceError,
17
15
 
18
- fields,
16
+ MISSING,
17
+ KW_ONLY,
19
18
 
20
- is_dataclass,
19
+ InitVar,
20
+ Field,
21
21
 
22
- replace,
23
- )
22
+ field,
24
23
 
25
- from .impl.api import ( # noqa
26
- dataclass as xdataclass,
24
+ dataclass,
25
+ make_dataclass,
27
26
 
28
- make_dataclass as xmake_dataclass,
27
+ fields,
29
28
 
30
- field as xfield,
31
- )
29
+ is_dataclass,
32
30
 
33
- from .impl.concerns.replace import ( # noqa
34
- replace as xreplace,
35
- )
31
+ replace,
32
+ )
36
33
 
37
- from .tools.as_ import ( # noqa
38
- asdict,
39
- astuple,
40
- )
34
+ from .impl.api import ( # noqa
35
+ dataclass as xdataclass,
41
36
 
37
+ make_dataclass as xmake_dataclass,
42
38
 
43
- ##
44
- # globals hack
39
+ field as xfield,
40
+ )
45
41
 
46
- globals()['field'] = xfield
42
+ from .impl.concerns.replace import ( # noqa
43
+ replace as xreplace,
44
+ )
47
45
 
48
- globals()['dataclass'] = xdataclass
49
- globals()['make_dataclass'] = xmake_dataclass
46
+ from .tools.as_ import ( # noqa
47
+ asdict,
48
+ astuple,
49
+ )
50
50
 
51
- globals()['replace'] = xreplace
51
+ ##
52
+ # additional interface
52
53
 
54
+ from .impl.api import ( # noqa
55
+ append_class_metadata,
56
+ extra_class_params,
57
+ init,
58
+ metadata,
59
+ validate,
53
60
 
54
- ##
55
- # additional interface
56
-
57
- from .impl.api import ( # noqa
58
- append_class_metadata,
59
- extra_class_params,
60
- init,
61
- metadata,
62
- validate,
63
-
64
- extra_field_params,
65
- set_field_metadata,
66
- update_extra_field_params,
67
- with_extra_field_params,
68
- )
61
+ extra_field_params,
62
+ set_field_metadata,
63
+ update_extra_field_params,
64
+ with_extra_field_params,
65
+ )
69
66
 
70
- from .errors import ( # noqa
71
- FieldFnValidationError,
72
- FieldTypeValidationError,
73
- FieldValidationError,
74
- FnValidationError,
75
- TypeValidationError,
76
- ValidationError,
77
- )
67
+ from .errors import ( # noqa
68
+ FieldFnValidationError,
69
+ FieldTypeValidationError,
70
+ FieldValidationError,
71
+ FnValidationError,
72
+ TypeValidationError,
73
+ ValidationError,
74
+ )
78
75
 
79
- from .metaclass.bases import ( # noqa
80
- Box,
81
- Case,
82
- Data,
83
- Frozen,
84
- )
76
+ from .metaclass.bases import ( # noqa
77
+ Box,
78
+ Case,
79
+ Data,
80
+ Frozen,
81
+ )
85
82
 
86
- from .metaclass.meta import ( # noqa
87
- DataMeta,
88
- )
83
+ from .metaclass.meta import ( # noqa
84
+ DataMeta,
85
+ )
89
86
 
90
- from .metaclass.specs import ( # noqa
91
- get_metaclass_spec,
92
- )
87
+ from .metaclass.specs import ( # noqa
88
+ get_metaclass_spec,
89
+ )
93
90
 
94
- from .reflection import ( # noqa
95
- reflect,
96
- )
91
+ from .reflection import ( # noqa
92
+ reflect,
93
+ )
97
94
 
98
- from .specs import ( # noqa
99
- CoerceFn,
100
- ValidateFn,
101
- ReprFn,
95
+ from .specs import ( # noqa
96
+ CoerceFn,
97
+ ValidateFn,
98
+ ReprFn,
102
99
 
103
- InitFn,
104
- ClassValidateFn,
100
+ InitFn,
101
+ ClassValidateFn,
105
102
 
106
- DefaultFactory,
103
+ DefaultFactory,
107
104
 
108
- FieldType,
105
+ FieldType,
109
106
 
110
- FieldSpec,
107
+ FieldSpec,
111
108
 
112
- ClassSpec,
113
- )
109
+ ClassSpec,
110
+ )
114
111
 
115
- from .tools.as_ import ( # noqa
116
- shallow_asdict,
117
- shallow_astuple,
118
- )
112
+ from .tools.as_ import ( # noqa
113
+ shallow_asdict,
114
+ shallow_astuple,
115
+ )
119
116
 
120
- from .tools.iter import ( # noqa
121
- fields_dict,
117
+ from .tools.iter import ( # noqa
118
+ fields_dict,
122
119
 
123
- iter_items,
124
- iter_keys,
125
- iter_values,
126
- )
120
+ iter_items,
121
+ iter_keys,
122
+ iter_values,
123
+ )
127
124
 
128
- from .tools.modifiers import ( # noqa
129
- field_modifier,
130
- update_fields,
131
- )
125
+ from .tools.modifiers import ( # noqa
126
+ field_modifier,
127
+ update_fields,
128
+ )
132
129
 
133
- from .tools.only_ import ( # noqa
134
- only,
135
- )
130
+ from .tools.only_ import ( # noqa
131
+ only,
132
+ )
136
133
 
137
- from .tools.replace import ( # noqa
138
- deep_replace,
139
- )
134
+ from .tools.replace import ( # noqa
135
+ deep_replace,
136
+ )
140
137
 
141
- from .tools.repr import ( # noqa
142
- opt_repr,
143
- truthy_repr,
144
- )
138
+ from .tools.repr import ( # noqa
139
+ opt_repr,
140
+ truthy_repr,
141
+ )
145
142
 
146
- from .tools.static import ( # noqa
147
- Static,
148
- )
143
+ from .tools.static import ( # noqa
144
+ Static,
145
+ )
146
+
147
+ ##
148
+ # lite imports
149
+
150
+ from ..lite.dataclasses import ( # noqa
151
+ is_immediate_dataclass,
152
+
153
+ dataclass_maybe_post_init as maybe_post_init,
154
+ )
149
155
 
150
156
 
151
157
  ##
152
- # lite imports
158
+ # globals hack
159
+
160
+ def _self_patching_global_proxy(l, r, ak_fn=None):
161
+ def inner(*args, **kwargs):
162
+ fn = getattr(_sys.modules[__name__], r)
163
+ globals()[l] = fn
164
+ if ak_fn:
165
+ args, kwargs = ak_fn(*args, **kwargs)
166
+ return fn(*args, **kwargs)
167
+ return inner
153
168
 
154
- from ..lite.dataclasses import ( # noqa
155
- is_immediate_dataclass,
156
169
 
157
- dataclass_maybe_post_init as maybe_post_init,
170
+ globals()['field'] = _self_patching_global_proxy('field', 'xfield')
171
+
172
+ globals()['dataclass'] = _self_patching_global_proxy('dataclass', 'xdataclass')
173
+
174
+ globals()['make_dataclass'] = _self_patching_global_proxy(
175
+ 'make_dataclass',
176
+ 'xmake_dataclass',
177
+ lambda *args, _frame_offset=1, **kwargs: (args, dict(_frame_offset=_frame_offset + 1, **kwargs)),
158
178
  )
179
+
180
+ globals()['replace'] = _self_patching_global_proxy('replace', 'xreplace')
@@ -55,6 +55,8 @@ def make_dataclass( # noqa
55
55
  terse_repr: bool | None = None,
56
56
 
57
57
  allow_redundant_decorator: bool | None = None,
58
+
59
+ _frame_offset: int = 1,
58
60
  ):
59
61
  if decorator is not dataclass:
60
62
  raise TypeError(
@@ -136,14 +138,14 @@ def make_dataclass( # noqa
136
138
 
137
139
  if _IS_PY_3_14:
138
140
  # For now, set annotations including the _ANY_MARKER.
139
- cls.__annotate__ = annotate_method # type: ignore
141
+ cls.__annotate__ = annotate_method # type: ignore # noqa
140
142
 
141
143
  if module is None:
142
144
  try:
143
- module = sys._getframemodulename(1) or '__main__' # type: ignore # noqa
145
+ module = sys._getframemodulename(_frame_offset) or '__main__' # type: ignore # noqa
144
146
  except AttributeError:
145
147
  with contextlib.suppress(AttributeError, ValueError):
146
- module = sys._getframe(1).f_globals.get('__name__', '__main__') # noqa
148
+ module = sys._getframe(_frame_offset).f_globals.get('__name__', '__main__') # noqa
147
149
  if module is not None:
148
150
  cls.__module__ = module
149
151
 
@@ -1,15 +1,10 @@
1
1
  import dataclasses as dc
2
- import importlib.resources
3
- import json
4
2
  import typing as ta
5
3
 
6
4
 
7
5
  ##
8
6
 
9
7
 
10
- PACKAGE_CONFIG_FILE_NAME = '.dataclasses.json'
11
-
12
-
13
8
  @dc.dataclass(frozen=True, kw_only=True)
14
9
  class PackageConfig:
15
10
  codegen: bool = False
@@ -17,15 +12,19 @@ class PackageConfig:
17
12
  def __init_subclass__(cls, **kwargs):
18
13
  raise TypeError
19
14
 
20
- @classmethod
21
- def loads(cls, s: str) -> 'PackageConfig':
22
- return cls(**json.loads(s))
23
15
 
24
- def dumps(self) -> str:
25
- return json.dumps(dc.asdict(self), indent=2)
16
+ DEFAULT_PACKAGE_CONFIG = PackageConfig()
26
17
 
27
18
 
28
- DEFAULT_PACKAGE_CONFIG = PackageConfig()
19
+ ##
20
+
21
+
22
+ def init_package(
23
+ name: str,
24
+ *,
25
+ codegen: bool = False,
26
+ ) -> None:
27
+ pass
29
28
 
30
29
 
31
30
  ##
@@ -46,24 +45,25 @@ class PackageConfigCache:
46
45
  ...
47
46
 
48
47
  def get(self, pkg, default=None):
49
- try:
50
- return self._dct[pkg]
51
- except KeyError:
52
- pass
53
-
54
- try:
55
- s = importlib.resources.read_text(pkg, PACKAGE_CONFIG_FILE_NAME)
56
- except FileNotFoundError:
57
- self._dct[pkg] = None
58
- else:
59
- c = PackageConfig.loads(s)
60
- self._dct[pkg] = c
61
- return c
62
-
63
- if '.' not in pkg:
64
- return default
65
-
66
- return self.get(pkg.rpartition('.')[0], default)
48
+ # try:
49
+ # return self._dct[pkg]
50
+ # except KeyError:
51
+ # pass
52
+ #
53
+ # try:
54
+ # s = importlib.resources.read_text(pkg, PACKAGE_CONFIG_FILE_NAME)
55
+ # except FileNotFoundError:
56
+ # self._dct[pkg] = None
57
+ # else:
58
+ # c = PackageConfig.loads(s)
59
+ # self._dct[pkg] = c
60
+ # return c
61
+ #
62
+ # if '.' not in pkg:
63
+ # return default
64
+ #
65
+ # return self.get(pkg.rpartition('.')[0], default)
66
+ return None
67
67
 
68
68
 
69
69
  PACKAGE_CONFIG_CACHE = PackageConfigCache()
omlish/lite/maysyncs.py CHANGED
@@ -100,6 +100,7 @@ class AnyMaysyncFn(abc.ABC, ta.Generic[_MaysyncRS, _MaysyncRA]): # noqa
100
100
  raise NotImplementedError
101
101
 
102
102
 
103
+ @ta.final
103
104
  class MaywaitableAlreadyConsumedError(Exception):
104
105
  pass
105
106
 
omlish/manifests/base.py CHANGED
@@ -15,7 +15,7 @@ class ModAttrManifest:
15
15
  module: str
16
16
  attr: str
17
17
 
18
- def load(self) -> ta.Any:
18
+ def resolve(self) -> ta.Any:
19
19
  import importlib # noqa
20
20
 
21
21
  mod = importlib.import_module(self.module)
@@ -1,4 +1,48 @@
1
- from .base import ( # noqa
1
+ """
2
+ TODO:
3
+ - redacted
4
+ - strongly typed MarshalerFactory base class?
5
+ - strongly typed Composite/Cached Marshaler/Unmarshaler factories - footgun
6
+ - streaming? Start/EndObject, etc..
7
+ - lang.Marker - class name, handle type[Foo]
8
+ - can't disambiguate from str - can't coexist in bare union
9
+ - factories being free MatchFns does more harm than good - in practice these are such big guns you want to write a
10
+ class body if only ceremonially
11
+
12
+ See:
13
+ - https://github.com/python-attrs/cattrs
14
+ - https://github.com/jcrist/msgspec
15
+ - https://github.com/Fatal1ty/mashumaro
16
+ - https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/serializers.md#custom-serializers
17
+ """
18
+
19
+
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
2
46
  Marshaler,
3
47
  Unmarshaler,
4
48
 
@@ -10,67 +54,55 @@ from .base import ( # noqa
10
54
 
11
55
  MarshalerFactory_,
12
56
  UnmarshalerFactory_,
57
+ )
58
+
59
+ from .base.values import ( # noqa
60
+ Value,
61
+ )
13
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
14
74
  SimpleMarshalerFactory,
15
75
  SimpleUnmarshalerFactory,
76
+ )
16
77
 
78
+ from .factories.match import ( # noqa
17
79
  MarshalerFactoryMatchClass,
18
80
  UnmarshalerFactoryMatchClass,
81
+ )
19
82
 
83
+ from .factories.multi import ( # noqa
20
84
  MultiMarshalerFactory,
21
85
  MultiUnmarshalerFactory,
86
+ )
22
87
 
88
+ from .factories.typemap import ( # noqa
23
89
  TypeMapMarshalerFactory,
24
90
  TypeMapUnmarshalerFactory,
91
+ )
25
92
 
93
+ from .factories.typecache import ( # noqa
26
94
  TypeCacheMarshalerFactory,
27
95
  TypeCacheUnmarshalerFactory,
96
+ )
28
97
 
98
+ from .factories.func import ( # noqa
29
99
  FuncMarshaler,
30
100
  FuncUnmarshaler,
101
+ )
31
102
 
32
- BaseContext,
33
- MarshalContext,
34
- UnmarshalContext,
35
-
103
+ from .factories.recursive import ( # noqa
36
104
  RecursiveMarshalerFactory,
37
105
  RecursiveUnmarshalerFactory,
38
-
39
- Override,
40
- ReflectOverride,
41
- )
42
-
43
- from .composite.iterables import ( # noqa
44
- IterableMarshaler,
45
- IterableUnmarshaler,
46
- )
47
-
48
- from .composite.wrapped import ( # noqa
49
- WrappedMarshaler,
50
- WrappedUnmarshaler,
51
- )
52
-
53
- from .errors import ( # noqa
54
- ForbiddenTypeError,
55
- MarshalError,
56
- UnhandledTypeError,
57
- )
58
-
59
- from .globals import ( # noqa
60
- GLOBAL_REGISTRY,
61
-
62
- global_marshaler_factory,
63
- marshal,
64
-
65
- global_unmarshaler_factory,
66
- unmarshal,
67
-
68
- register_global,
69
- )
70
-
71
- from .naming import ( # noqa
72
- Naming,
73
- translate_name,
74
106
  )
75
107
 
76
108
  from .objects.dataclasses import ( # noqa
@@ -152,20 +184,6 @@ from .singular.primitives import ( # noqa
152
184
  PRIMITIVE_TYPES,
153
185
  )
154
186
 
155
- from .registries import ( # noqa
156
- Registry,
157
- )
158
-
159
- from .standard import ( # noqa
160
- STANDARD_MARSHALER_FACTORIES,
161
- new_standard_marshaler_factory,
162
-
163
- STANDARD_UNMARSHALER_FACTORIES,
164
- new_standard_unmarshaler_factory,
165
-
166
- install_standard_factories,
167
- )
168
-
169
187
  from .trivial.forbidden import ( # noqa
170
188
  ForbiddenTypeMarshalerFactory,
171
189
  ForbiddenTypeUnmarshalerFactory,
@@ -176,8 +194,31 @@ from .trivial.nop import ( # noqa
176
194
  NopMarshalerUnmarshaler,
177
195
  )
178
196
 
179
- from .values import ( # noqa
180
- Value,
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,
181
222
  )
182
223
 
183
224
 
File without changes