omlish 0.0.0.dev372__py3-none-any.whl → 0.0.0.dev373__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/lite/marshal.py +63 -4
- {omlish-0.0.0.dev372.dist-info → omlish-0.0.0.dev373.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev372.dist-info → omlish-0.0.0.dev373.dist-info}/RECORD +8 -8
- {omlish-0.0.0.dev372.dist-info → omlish-0.0.0.dev373.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev372.dist-info → omlish-0.0.0.dev373.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev372.dist-info → omlish-0.0.0.dev373.dist-info}/licenses/LICENSE +0 -0
- {omlish-0.0.0.dev372.dist-info → omlish-0.0.0.dev373.dist-info}/top_level.txt +0 -0
omlish/__about__.py
CHANGED
omlish/lite/marshal.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
"""
|
2
2
|
TODO:
|
3
3
|
- pickle stdlib objs? have to pin to 3.8 pickle protocol, will be cross-version
|
4
|
-
- literals
|
5
4
|
- Options.sequence_cls = list, mapping_cls = dict, ... - def with_mutable_containers() -> Options
|
6
5
|
"""
|
7
6
|
# ruff: noqa: UP006 UP007 UP045
|
@@ -24,7 +23,6 @@ from .check import check
|
|
24
23
|
from .reflect import deep_subclasses
|
25
24
|
from .reflect import get_literal_type_args
|
26
25
|
from .reflect import get_new_type_supertype
|
27
|
-
from .reflect import get_optional_alias_arg
|
28
26
|
from .reflect import is_generic_alias
|
29
27
|
from .reflect import is_literal_type
|
30
28
|
from .reflect import is_new_type
|
@@ -144,6 +142,28 @@ class OptionalObjMarshaler(ObjMarshaler):
|
|
144
142
|
return self.item.unmarshal(o, ctx)
|
145
143
|
|
146
144
|
|
145
|
+
@dc.dataclass(frozen=True)
|
146
|
+
class PrimitiveUnionObjMarshaler(ObjMarshaler):
|
147
|
+
pt: ta.Tuple[type, ...]
|
148
|
+
x: ta.Optional[ObjMarshaler] = None
|
149
|
+
|
150
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
151
|
+
if isinstance(o, self.pt):
|
152
|
+
return o
|
153
|
+
elif self.x is not None:
|
154
|
+
return self.x.marshal(o, ctx)
|
155
|
+
else:
|
156
|
+
raise TypeError(o)
|
157
|
+
|
158
|
+
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
159
|
+
if isinstance(o, self.pt):
|
160
|
+
return o
|
161
|
+
elif self.x is not None:
|
162
|
+
return self.x.unmarshal(o, ctx)
|
163
|
+
else:
|
164
|
+
raise TypeError(o)
|
165
|
+
|
166
|
+
|
147
167
|
@dc.dataclass(frozen=True)
|
148
168
|
class LiteralObjMarshaler(ObjMarshaler):
|
149
169
|
item: ObjMarshaler
|
@@ -342,6 +362,13 @@ _OBJ_MARSHALER_GENERIC_ITERABLE_TYPES: ta.Dict[ta.Any, type] = {
|
|
342
362
|
collections.abc.MutableSequence: list,
|
343
363
|
}
|
344
364
|
|
365
|
+
_OBJ_MARSHALER_PRIMITIVE_TYPES: ta.Set[type] = {
|
366
|
+
int,
|
367
|
+
float,
|
368
|
+
bool,
|
369
|
+
str,
|
370
|
+
}
|
371
|
+
|
345
372
|
|
346
373
|
##
|
347
374
|
|
@@ -490,8 +517,16 @@ class ObjMarshalerManager:
|
|
490
517
|
|
491
518
|
if is_literal_type(ty):
|
492
519
|
lvs = frozenset(get_literal_type_args(ty))
|
520
|
+
if None in lvs:
|
521
|
+
is_opt = True
|
522
|
+
lvs -= frozenset([None])
|
523
|
+
else:
|
524
|
+
is_opt = False
|
493
525
|
lty = check.single(set(map(type, lvs)))
|
494
|
-
|
526
|
+
lm: ObjMarshaler = LiteralObjMarshaler(rec(lty), lvs)
|
527
|
+
if is_opt:
|
528
|
+
lm = OptionalObjMarshaler(lm)
|
529
|
+
return lm
|
495
530
|
|
496
531
|
if is_generic_alias(ty):
|
497
532
|
try:
|
@@ -511,7 +546,31 @@ class ObjMarshalerManager:
|
|
511
546
|
return IterableObjMarshaler(st, rec(e))
|
512
547
|
|
513
548
|
if is_union_alias(ty):
|
514
|
-
|
549
|
+
uts = frozenset(ta.get_args(ty))
|
550
|
+
if None in uts or type(None) in uts:
|
551
|
+
is_opt = True
|
552
|
+
uts = frozenset(ut for ut in uts if ut not in (None, type(None)))
|
553
|
+
else:
|
554
|
+
is_opt = False
|
555
|
+
|
556
|
+
um: ObjMarshaler
|
557
|
+
if not uts:
|
558
|
+
raise TypeError(ty)
|
559
|
+
elif len(uts) == 1:
|
560
|
+
um = rec(check.single(uts))
|
561
|
+
else:
|
562
|
+
pt = tuple({ut for ut in uts if ut in _OBJ_MARSHALER_PRIMITIVE_TYPES})
|
563
|
+
np_uts = {ut for ut in uts if ut not in _OBJ_MARSHALER_PRIMITIVE_TYPES}
|
564
|
+
if not np_uts:
|
565
|
+
um = PrimitiveUnionObjMarshaler(pt)
|
566
|
+
elif len(np_uts) == 1:
|
567
|
+
um = PrimitiveUnionObjMarshaler(pt, x=rec(check.single(np_uts)))
|
568
|
+
else:
|
569
|
+
raise TypeError(ty)
|
570
|
+
|
571
|
+
if is_opt:
|
572
|
+
um = OptionalObjMarshaler(um)
|
573
|
+
return um
|
515
574
|
|
516
575
|
raise TypeError(ty)
|
517
576
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
omlish/.manifests.json,sha256=aT8yZ-Zh-9wfHl5Ym5ouiWC1i0cy7Q7RlhzavB6VLPI,8587
|
2
|
-
omlish/__about__.py,sha256=
|
2
|
+
omlish/__about__.py,sha256=a_E5lH9U0Zxuae2uxWKtn3a6hmcIp8G2BThTgUgh_H0,3478
|
3
3
|
omlish/__init__.py,sha256=SsyiITTuK0v74XpKV8dqNaCmjOlan1JZKrHQv5rWKPA,253
|
4
4
|
omlish/c3.py,sha256=rer-TPOFDU6fYq_AWio_AmA-ckZ8JDY5shIzQ_yXfzA,8414
|
5
5
|
omlish/cached.py,sha256=MLap_p0rdGoDIMVhXVHm1tsbcWobJF0OanoodV03Ju8,542
|
@@ -472,7 +472,7 @@ omlish/lite/imports.py,sha256=JDYRFxu-ofHEBfd5VV3b27oKOLhtTpuzte1_Nt7yLgw,1352
|
|
472
472
|
omlish/lite/inject.py,sha256=xvmLmtD3_2INnkurJQv76_Rkh9usbApEQrXJ4cvuVAk,29019
|
473
473
|
omlish/lite/json.py,sha256=7-02Ny4fq-6YAu5ynvqoijhuYXWpLmfCI19GUeZnb1c,740
|
474
474
|
omlish/lite/logs.py,sha256=CWFG0NKGhqNeEgryF5atN2gkPYbUdTINEw_s1phbINM,51
|
475
|
-
omlish/lite/marshal.py,sha256=
|
475
|
+
omlish/lite/marshal.py,sha256=dxiDtmSXt4EBpTprMNkPsOYkRs0W9AC3Kby9UGEjuRo,20400
|
476
476
|
omlish/lite/maybes.py,sha256=0p_fzb6yiOjEpvMKaQ53Q6CH1VPW1or7v7Lt1JIKcgM,4359
|
477
477
|
omlish/lite/pycharm.py,sha256=FRHGcCDo42UzZXqNwW_DkhI-6kb_CmJKPiQ8F6mYkLA,1174
|
478
478
|
omlish/lite/reflect.py,sha256=pzOY2PPuHH0omdtglkN6DheXDrGopdL3PtTJnejyLFU,2189
|
@@ -888,9 +888,9 @@ omlish/typedvalues/marshal.py,sha256=AtBz7Jq-BfW8vwM7HSxSpR85JAXmxK2T0xDblmm1HI0
|
|
888
888
|
omlish/typedvalues/of_.py,sha256=UXkxSj504WI2UrFlqdZJbu2hyDwBhL7XVrc2qdR02GQ,1309
|
889
889
|
omlish/typedvalues/reflect.py,sha256=PAvKW6T4cW7u--iX80w3HWwZUS3SmIZ2_lQjT65uAyk,1026
|
890
890
|
omlish/typedvalues/values.py,sha256=ym46I-q2QJ_6l4UlERqv3yj87R-kp8nCKMRph0xQ3UA,1307
|
891
|
-
omlish-0.0.0.
|
892
|
-
omlish-0.0.0.
|
893
|
-
omlish-0.0.0.
|
894
|
-
omlish-0.0.0.
|
895
|
-
omlish-0.0.0.
|
896
|
-
omlish-0.0.0.
|
891
|
+
omlish-0.0.0.dev373.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
|
892
|
+
omlish-0.0.0.dev373.dist-info/METADATA,sha256=fed55fYjKmKimj_-64adhKjxXvjVgpztmAzJhqRHczs,4416
|
893
|
+
omlish-0.0.0.dev373.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
894
|
+
omlish-0.0.0.dev373.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
|
895
|
+
omlish-0.0.0.dev373.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
|
896
|
+
omlish-0.0.0.dev373.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|