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.
- omlish/__about__.py +2 -3
- omlish/codecs/registry.py +1 -1
- omlish/dataclasses/__init__.py +135 -113
- omlish/dataclasses/impl/api/classes/make.py +5 -3
- omlish/dataclasses/impl/configs.py +29 -29
- omlish/lite/maysyncs.py +1 -0
- omlish/manifests/base.py +1 -1
- omlish/marshal/__init__.py +98 -57
- omlish/marshal/base/__init__.py +0 -0
- omlish/marshal/base/contexts.py +75 -0
- omlish/marshal/{errors.py → base/errors.py} +1 -1
- omlish/marshal/base/options.py +2 -0
- omlish/marshal/base/overrides.py +25 -0
- omlish/marshal/{registries.py → base/registries.py} +4 -8
- omlish/marshal/base/types.py +70 -0
- omlish/marshal/{values.py → base/values.py} +1 -13
- omlish/marshal/composite/iterables.py +7 -7
- omlish/marshal/composite/literals.py +7 -7
- omlish/marshal/composite/mappings.py +7 -7
- omlish/marshal/composite/maybes.py +7 -7
- omlish/marshal/composite/newtypes.py +6 -6
- omlish/marshal/composite/optionals.py +7 -7
- omlish/marshal/composite/special.py +6 -6
- omlish/marshal/composite/wrapped.py +5 -5
- omlish/marshal/factories/__init__.py +0 -0
- omlish/marshal/factories/func.py +28 -0
- omlish/marshal/factories/match.py +34 -0
- omlish/marshal/factories/multi.py +55 -0
- omlish/marshal/factories/recursive.py +120 -0
- omlish/marshal/factories/simple.py +28 -0
- omlish/marshal/factories/typecache.py +91 -0
- omlish/marshal/factories/typemap.py +65 -0
- omlish/marshal/globals.py +7 -7
- omlish/marshal/naming.py +1 -1
- omlish/marshal/objects/dataclasses.py +7 -7
- omlish/marshal/objects/marshal.py +4 -4
- omlish/marshal/objects/metadata.py +4 -4
- omlish/marshal/objects/namedtuples.py +7 -7
- omlish/marshal/objects/unmarshal.py +4 -4
- omlish/marshal/polymorphism/marshal.py +4 -4
- omlish/marshal/polymorphism/metadata.py +1 -1
- omlish/marshal/polymorphism/standard.py +2 -2
- omlish/marshal/polymorphism/unions.py +7 -7
- omlish/marshal/polymorphism/unmarshal.py +4 -4
- omlish/marshal/singular/base64.py +7 -7
- omlish/marshal/singular/datetimes.py +7 -7
- omlish/marshal/singular/enums.py +7 -7
- omlish/marshal/singular/numbers.py +7 -7
- omlish/marshal/singular/primitives.py +7 -7
- omlish/marshal/singular/uuids.py +7 -7
- omlish/marshal/standard.py +8 -8
- omlish/marshal/trivial/any.py +7 -7
- omlish/marshal/trivial/forbidden.py +7 -7
- omlish/marshal/trivial/nop.py +5 -5
- {omlish-0.0.0.dev414.dist-info → omlish-0.0.0.dev415.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev414.dist-info → omlish-0.0.0.dev415.dist-info}/RECORD +60 -52
- omlish/inject/.dataclasses.json +0 -3
- omlish/marshal/.dataclasses.json +0 -3
- omlish/marshal/base.py +0 -472
- omlish/marshal/factories.py +0 -116
- omlish/marshal/proxy.py +0 -26
- {omlish-0.0.0.dev414.dist-info → omlish-0.0.0.dev415.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev414.dist-info → omlish-0.0.0.dev415.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev414.dist-info → omlish-0.0.0.dev415.dist-info}/licenses/LICENSE +0 -0
- {omlish-0.0.0.dev414.dist-info → omlish-0.0.0.dev415.dist-info}/top_level.txt +0 -0
omlish/marshal/factories.py
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
import dataclasses as dc
|
2
|
-
import threading
|
3
|
-
import typing as ta
|
4
|
-
|
5
|
-
from .. import check
|
6
|
-
from .. import reflect as rfl
|
7
|
-
from ..funcs import match as mfs
|
8
|
-
|
9
|
-
|
10
|
-
R = ta.TypeVar('R')
|
11
|
-
C = ta.TypeVar('C')
|
12
|
-
|
13
|
-
|
14
|
-
##
|
15
|
-
|
16
|
-
|
17
|
-
@dc.dataclass(frozen=True)
|
18
|
-
class TypeMapFactory(mfs.MatchFn[[C, rfl.Type], R]):
|
19
|
-
m: ta.Mapping[rfl.Type, R] = dc.field(default_factory=dict)
|
20
|
-
|
21
|
-
def __post_init__(self) -> None:
|
22
|
-
for k in self.m:
|
23
|
-
if not isinstance(k, rfl.TYPES):
|
24
|
-
raise TypeError(k)
|
25
|
-
|
26
|
-
def guard(self, ctx: C, rty: rfl.Type) -> bool:
|
27
|
-
check.isinstance(rty, rfl.TYPES)
|
28
|
-
return rty in self.m
|
29
|
-
|
30
|
-
def fn(self, ctx: C, rty: rfl.Type) -> R:
|
31
|
-
check.isinstance(rty, rfl.TYPES)
|
32
|
-
try:
|
33
|
-
return self.m[rty]
|
34
|
-
except KeyError:
|
35
|
-
raise mfs.MatchGuardError(ctx, rty) # noqa
|
36
|
-
|
37
|
-
|
38
|
-
##
|
39
|
-
|
40
|
-
|
41
|
-
class TypeCacheFactory(mfs.MatchFn[[C, rfl.Type], R]):
|
42
|
-
def __init__(self, f: mfs.MatchFn[[C, rfl.Type], R]) -> None:
|
43
|
-
super().__init__()
|
44
|
-
|
45
|
-
self._f = f
|
46
|
-
self._dct: dict[rfl.Type, R | None] = {}
|
47
|
-
self._mtx = threading.RLock()
|
48
|
-
|
49
|
-
def guard(self, ctx: C, rty: rfl.Type) -> bool:
|
50
|
-
check.isinstance(rty, rfl.TYPES)
|
51
|
-
with self._mtx:
|
52
|
-
try:
|
53
|
-
e = self._dct[rty]
|
54
|
-
except KeyError:
|
55
|
-
if self._f.guard(ctx, rty):
|
56
|
-
return True
|
57
|
-
else:
|
58
|
-
self._dct[rty] = None
|
59
|
-
return False
|
60
|
-
else:
|
61
|
-
return e is not None
|
62
|
-
|
63
|
-
def fn(self, ctx: C, rty: rfl.Type) -> R:
|
64
|
-
check.isinstance(rty, rfl.TYPES)
|
65
|
-
with self._mtx:
|
66
|
-
try:
|
67
|
-
e = self._dct[rty]
|
68
|
-
except KeyError:
|
69
|
-
try:
|
70
|
-
ret = self._f(ctx, rty)
|
71
|
-
except mfs.MatchGuardError:
|
72
|
-
self._dct[rty] = None
|
73
|
-
raise
|
74
|
-
else:
|
75
|
-
self._dct[rty] = ret
|
76
|
-
return ret
|
77
|
-
else:
|
78
|
-
if e is None:
|
79
|
-
raise mfs.MatchGuardError(ctx, rty)
|
80
|
-
else:
|
81
|
-
return e
|
82
|
-
|
83
|
-
|
84
|
-
##
|
85
|
-
|
86
|
-
|
87
|
-
class RecursiveTypeFactory(mfs.MatchFn[[C, rfl.Type], R]):
|
88
|
-
def __init__(
|
89
|
-
self,
|
90
|
-
f: mfs.MatchFn[[C, rfl.Type], R],
|
91
|
-
prx: ta.Callable[[], tuple[R, ta.Callable[[R], None]]],
|
92
|
-
) -> None:
|
93
|
-
super().__init__()
|
94
|
-
|
95
|
-
self._f = f
|
96
|
-
self._prx = prx
|
97
|
-
self._dct: dict[rfl.Type, R] = {}
|
98
|
-
|
99
|
-
def guard(self, ctx: C, rty: rfl.Type) -> bool:
|
100
|
-
check.isinstance(rty, rfl.TYPES)
|
101
|
-
return self._f.guard(ctx, rty)
|
102
|
-
|
103
|
-
def fn(self, ctx: C, rty: rfl.Type) -> R:
|
104
|
-
check.isinstance(rty, rfl.TYPES)
|
105
|
-
try:
|
106
|
-
return self._dct[rty]
|
107
|
-
except KeyError:
|
108
|
-
pass
|
109
|
-
p, sp = self._prx()
|
110
|
-
self._dct[rty] = p
|
111
|
-
try:
|
112
|
-
r = self._f(ctx, rty)
|
113
|
-
sp(r)
|
114
|
-
return r
|
115
|
-
finally:
|
116
|
-
del self._dct[rty]
|
omlish/marshal/proxy.py
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
import typing as ta
|
2
|
-
|
3
|
-
|
4
|
-
T = ta.TypeVar('T')
|
5
|
-
|
6
|
-
|
7
|
-
##
|
8
|
-
|
9
|
-
|
10
|
-
class _Proxy(ta.Generic[T]):
|
11
|
-
__obj: T | None = None
|
12
|
-
|
13
|
-
@property
|
14
|
-
def _obj(self) -> T:
|
15
|
-
if self.__obj is None:
|
16
|
-
raise TypeError('recursive proxy not set')
|
17
|
-
return self.__obj
|
18
|
-
|
19
|
-
def _set_obj(self, obj: T) -> None:
|
20
|
-
if self.__obj is not None:
|
21
|
-
raise TypeError('recursive proxy already set')
|
22
|
-
self.__obj = obj
|
23
|
-
|
24
|
-
@classmethod
|
25
|
-
def _new(cls) -> tuple[ta.Any, ta.Callable[[ta.Any], None]]:
|
26
|
-
return (p := cls()), p._set_obj # noqa
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|