From 48be65825870651758586223d3fc260d125168cb Mon Sep 17 00:00:00 2001 From: Niraj Kamdar Date: Sat, 3 Jun 2023 14:10:26 +0530 Subject: [PATCH] refactor: polywrap-msgpack package --- packages/polywrap-msgpack/polywrap_msgpack/__init__.py | 7 ++++++- packages/polywrap-msgpack/polywrap_msgpack/decoder.py | 4 ++-- packages/polywrap-msgpack/polywrap_msgpack/encoder.py | 8 ++++++-- packages/polywrap-msgpack/polywrap_msgpack/sanitize.py | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/polywrap-msgpack/polywrap_msgpack/__init__.py b/packages/polywrap-msgpack/polywrap_msgpack/__init__.py index fbf10d10..096032d9 100644 --- a/packages/polywrap-msgpack/polywrap_msgpack/__init__.py +++ b/packages/polywrap-msgpack/polywrap_msgpack/__init__.py @@ -14,13 +14,18 @@ from .sanitize import * __all__ = [ + # Serializer "msgpack_decode", "msgpack_encode", + # Extensions "decode_ext_hook", "encode_ext_hook", - "sanitize", "ExtensionTypes", + # Sanitizers + "sanitize", + # Extention types "GenericMap", + # Errors "MsgpackError", "MsgpackDecodeError", "MsgpackEncodeError", diff --git a/packages/polywrap-msgpack/polywrap_msgpack/decoder.py b/packages/polywrap-msgpack/polywrap_msgpack/decoder.py index 9d78a9d7..a768be9b 100644 --- a/packages/polywrap-msgpack/polywrap_msgpack/decoder.py +++ b/packages/polywrap-msgpack/polywrap_msgpack/decoder.py @@ -43,8 +43,8 @@ def msgpack_decode(val: bytes) -> Any: Any: any python object """ try: - return msgpack.unpackb( + return msgpack.unpackb( # pyright: ignore[reportUnknownMemberType] val, ext_hook=decode_ext_hook - ) # pyright: reportUnknownMemberType=false + ) except Exception as e: raise MsgpackDecodeError("Failed to decode msgpack data") from e diff --git a/packages/polywrap-msgpack/polywrap_msgpack/encoder.py b/packages/polywrap-msgpack/polywrap_msgpack/encoder.py index a74642b1..71ea9c16 100644 --- a/packages/polywrap-msgpack/polywrap_msgpack/encoder.py +++ b/packages/polywrap-msgpack/polywrap_msgpack/encoder.py @@ -28,8 +28,12 @@ def encode_ext_hook(obj: Any) -> ExtType: return ExtType( ExtensionTypes.GENERIC_MAP.value, # pylint: disable=protected-access - msgpack_encode(cast(GenericMap[Any, Any], obj)._map), - ) # pyright: reportPrivateUsage=false + msgpack_encode( + cast( + GenericMap[Any, Any], obj + )._map # pyright: ignore[reportPrivateUsage] + ), + ) raise MsgpackExtError(f"Object of type {type(obj)} is not supported") diff --git a/packages/polywrap-msgpack/polywrap_msgpack/sanitize.py b/packages/polywrap-msgpack/polywrap_msgpack/sanitize.py index e2982e36..93d8ba1b 100644 --- a/packages/polywrap-msgpack/polywrap_msgpack/sanitize.py +++ b/packages/polywrap-msgpack/polywrap_msgpack/sanitize.py @@ -22,7 +22,7 @@ def sanitize(value: Any) -> Any: if isinstance(value, GenericMap): dictionary: Dict[Any, Any] = cast( GenericMap[Any, Any], value - )._map # pyright: reportPrivateUsage=false + )._map # pyright: ignore[reportPrivateUsage] new_map: GenericMap[str, Any] = GenericMap({}) for key, val in dictionary.items(): if not isinstance(key, str):