Compare commits

..

No commits in common. "acf6f123a91edb42b240e01b748ab3b5cc3b1b5d" and "8077487efc2bbd5f43724be27c6ef2cbe400e649" have entirely different histories.

3 changed files with 23 additions and 53 deletions

View File

@ -211,28 +211,24 @@ def mk_dec(
and and
ext_types is None ext_types is None
): ):
raise TypeError( raise ValueError(
f'MIssing type-`spec` for msg decoder!\n' f'You must provide a type-spec for a msg decoder!\n'
f'\n' f'The only time `spec=None` is permitted is if custom extension types '
f'`spec=None` is **only** permitted is if custom extension types ' f'are expected to be supported, in which case `ext_types` must be non-`None`'
f'are provided via `ext_types`, meaning it must be non-`None`.\n' f'and it is presumed that only the `ext_types` (supported by the paired `dec_hook()`) '
f'\n' f'will be permitted within the type-`spec`!\n'
f'In this case it is presumed that only the `ext_types`, '
f'which much be handled by a paired `dec_hook()`, ' f'tpec = {spec!r}\n'
f'will be permitted within the payload type-`spec`!\n'
f'\n'
f'spec = {spec!r}\n'
f'dec_hook = {dec_hook!r}\n' f'dec_hook = {dec_hook!r}\n'
f'ext_types = {ext_types!r}\n' f'ext_types = {ext_types!r}\n'
) )
if dec_hook: if dec_hook:
if ext_types is None: if ext_types is None:
raise TypeError( raise ValueError(
f'If extending the serializable types with a custom decode hook (`dec_hook()`), ' f'If extending the serializable types with a custom decoder hook, '
f'you must also provide the expected type set that the hook will handle ' f'you must also provide the expected type set `dec_hook()` will handle '
f'via a `ext_types: Union[Type]|None = None` argument!\n' f'via the `ext_types: Union[Type]|None = None` argument!\n'
f'\n'
f'dec_hook = {dec_hook!r}\n' f'dec_hook = {dec_hook!r}\n'
f'ext_types = {ext_types!r}\n' f'ext_types = {ext_types!r}\n'
) )
@ -291,7 +287,7 @@ def unpack_spec_types(
When `spec` is not a type-union returns `{spec,}`. When `spec` is not a type-union returns `{spec,}`.
''' '''
spec_subtypes: set[Union[Type]] = set( spec_subtypes: set[Union[Type]] = (
getattr( getattr(
spec, spec,
'__args__', '__args__',
@ -453,7 +449,6 @@ class MsgCodec(Struct):
# |_BufferError: Existing exports of data: object cannot be re-sized # |_BufferError: Existing exports of data: object cannot be re-sized
as_ext_type: bool = False, as_ext_type: bool = False,
hide_tb: bool = True,
) -> bytes: ) -> bytes:
''' '''
@ -464,21 +459,11 @@ class MsgCodec(Struct):
https://jcristharif.com/msgspec/perf-tips.html#reusing-an-output-buffer https://jcristharif.com/msgspec/perf-tips.html#reusing-an-output-buffer
''' '''
__tracebackhide__: bool = hide_tb
if use_buf: if use_buf:
self._enc.encode_into(py_obj, self._buf) self._enc.encode_into(py_obj, self._buf)
return self._buf return self._buf
return self._enc.encode(py_obj) return self._enc.encode(py_obj)
# try:
# return self._enc.encode(py_obj)
# except TypeError as typerr:
# typerr.add_note(
# '|_src error from `msgspec`'
# # f'|_{self._enc.encode!r}'
# )
# raise typerr
# TODO! REMOVE once i'm confident we won't ever need it! # TODO! REMOVE once i'm confident we won't ever need it!
# #
# box: Struct = self._ext_types_box # box: Struct = self._ext_types_box
@ -587,11 +572,10 @@ def mk_codec(
pld_spec = ipc_pld_spec pld_spec = ipc_pld_spec
if enc_hook: if enc_hook:
if not ext_types: if not ext_types:
raise TypeError( raise ValueError(
f'If extending the serializable types with a custom encode hook (`enc_hook()`), ' f'If extending the serializable types with a custom decoder hook, '
f'you must also provide the expected type set that the hook will handle ' f'you must also provide the expected type set `enc_hook()` will handle '
f'via a `ext_types: Union[Type]|None = None` argument!\n' f'via the `ext_types: Union[Type]|None = None` argument!\n'
f'\n'
f'enc_hook = {enc_hook!r}\n' f'enc_hook = {enc_hook!r}\n'
f'ext_types = {ext_types!r}\n' f'ext_types = {ext_types!r}\n'
) )

View File

@ -33,9 +33,6 @@ converters,
|_ https://jcristharif.com/msgspec/changelog.html |_ https://jcristharif.com/msgspec/changelog.html
''' '''
from types import (
ModuleType,
)
import typing import typing
from typing import ( from typing import (
Type, Type,
@ -44,20 +41,19 @@ from typing import (
def dec_type_union( def dec_type_union(
type_names: list[str], type_names: list[str],
mods: list[ModuleType] = [] ) -> Type:
) -> Type|Union[Type]:
''' '''
Look up types by name, compile into a list and then create and Look up types by name, compile into a list and then create and
return a `typing.Union` from the full set. return a `typing.Union` from the full set.
''' '''
# import importlib import importlib
types: list[Type] = [] types: list[Type] = []
for type_name in type_names: for type_name in type_names:
for mod in [ for mod in [
typing, typing,
# importlib.import_module(__name__), importlib.import_module(__name__),
] + mods: ]:
if type_ref := getattr( if type_ref := getattr(
mod, mod,
type_name, type_name,

View File

@ -461,16 +461,11 @@ def limit_plds(
''' '''
__tracebackhide__: bool = True __tracebackhide__: bool = True
curr_ctx: Context|None = current_ipc_ctx()
if curr_ctx is None:
raise RuntimeError(
'No IPC `Context` is active !?\n'
'Did you open `limit_plds()` from outside '
'a `Portal.open_context()` scope-block?'
)
try: try:
curr_ctx: Context = current_ipc_ctx()
rx: PldRx = curr_ctx._pld_rx rx: PldRx = curr_ctx._pld_rx
orig_pldec: MsgDec = rx.pld_dec orig_pldec: MsgDec = rx.pld_dec
with rx.limit_plds( with rx.limit_plds(
spec=spec, spec=spec,
**dec_kwargs, **dec_kwargs,
@ -480,11 +475,6 @@ def limit_plds(
f'{pldec}\n' f'{pldec}\n'
) )
yield pldec yield pldec
except BaseException:
__tracebackhide__: bool = False
raise
finally: finally:
log.runtime( log.runtime(
'Reverted to previous payload-decoder\n\n' 'Reverted to previous payload-decoder\n\n'