Always merge input `spec` with any `ext_types`
That is, in `.msg._codec.mk_dec()` to ensure we actually still respect the provided `spec: Union[Type[Struct]]|Type|None` alongside any "custom" extension-types expected to be `dec_hook()` pre-processed. Notes, - previously when `dec_hook()` was provided we were merging with a `msgspec.Raw` instead of `spec` which **is entirely wrong**; it was likely leftover code from the sloppy/naive first draft of extension types support. - notice the `spec: Union[Type[Struct]]|Type|None` type annotation (and it appears as though a `test_ext_types_msgspec` suite actually passes the value `spec=None` fyi) with a value of `None` to imply merging as `Union[ext_types]|None` (or equivalently a `Optional[Union]`), due to the incorrect `Raw`-default usage this was actually being ignored.. -> this case has now been clarified via comment in the fn-signature.pld_dec_refinements
parent
ccedee3b87
commit
224e92b468
|
@ -181,7 +181,11 @@ class MsgDec(Struct):
|
|||
|
||||
|
||||
def mk_dec(
|
||||
spec: Union[Type[Struct]]|Type|None,
|
||||
spec: (
|
||||
Union[Type[Struct]]
|
||||
|Type # lone type
|
||||
|None # implying `Union[*ext_types]|None`
|
||||
),
|
||||
|
||||
# NOTE, required for ad-hoc type extensions to the underlying
|
||||
# serialization proto (which is default `msgpack`),
|
||||
|
@ -194,16 +198,18 @@ def mk_dec(
|
|||
Create an IPC msg decoder, a slightly higher level wrapper around
|
||||
a `msgspec.msgpack.Decoder` which provides,
|
||||
|
||||
- easier introspection of the underlying type spec via
|
||||
the `.spec` and `.spec_str` attrs,
|
||||
- easier introspection of the underlying type spec via the
|
||||
`.spec` and `.spec_str` attrs,
|
||||
- `.hook` access to the `Decoder.dec_hook()`,
|
||||
- automatic custom extension-types decode support when
|
||||
`dec_hook()` is provided such that any `PayloadMsg.pld` tagged
|
||||
as a type from from `ext_types` (presuming the `MsgCodec.encode()` also used
|
||||
a `.enc_hook()`) is processed and constructed by a `PldRx` implicitily.
|
||||
as a type from from `ext_types` (presuming the
|
||||
`MsgCodec.encode()` also used a `.enc_hook()`) is processed and
|
||||
constructed by a `PldRx` implicitily.
|
||||
|
||||
NOTE, as mentioned a `MsgDec` is normally used for `PayloadMsg.pld: PayloadT` field
|
||||
decoding inside an IPC-ctx-oriented `PldRx`.
|
||||
NOTE, as mentioned a `MsgDec` is normally used for
|
||||
`PayloadMsg.pld: PayloadT` field decoding inside an
|
||||
IPC-ctx-oriented `PldRx`.
|
||||
|
||||
'''
|
||||
if (
|
||||
|
@ -248,7 +254,8 @@ def mk_dec(
|
|||
# will work? kk B)
|
||||
#
|
||||
# maybe_box_struct = mk_boxed_ext_struct(ext_types)
|
||||
spec = Raw | Union[*ext_types]
|
||||
|
||||
spec = spec | Union[*ext_types]
|
||||
|
||||
return MsgDec(
|
||||
_dec=msgpack.Decoder(
|
||||
|
|
Loading…
Reference in New Issue