From 224e92b46872b04674091eb0299046848f52c72a Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 25 Sep 2025 19:24:58 -0400 Subject: [PATCH] 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. --- tractor/msg/_codec.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tractor/msg/_codec.py b/tractor/msg/_codec.py index 1e9623af..9801d46b 100644 --- a/tractor/msg/_codec.py +++ b/tractor/msg/_codec.py @@ -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(