Type hints for msgpack #1089
-
|
Hello. The code snippet below is to serialize/deserialize python objects including numpy arrays using msgpack (in combination with msgpack_numpy): This for Python 3.9+. Thank-you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
I'm not familiar with numpy or msgpack, but I'll try to answer your questions as well as I can. The In the calls to with somedb('mydb', 'w') as db:
...As I assume that with somedb('mydb':str, 'r':str) as db:
this_list: list = msgpack_deserialize(db.read('a_list'))
this_array: npt.ArrayLike = msgpack_deserialize(db.read('an_array')) |
Beta Was this translation helpful? Give feedback.
I'm not familiar with numpy or msgpack, but I'll try to answer your questions as well as I can.
The
valuearguments tomsgpack_serialize()andmsgpack_deserialize()are just passed on tomsgpack.packb()andunpackb(), respectively. Whilemsgpackhas no type hints, at leastunpackb()could probably simply be annotated usingbytes:def msgpack_deserialize(value: bytes):. I couldn't find the definition ofpackb(), so I don't know how to best annotate it.In the calls to
somedb()you are trying to annotate the passed arguments. This doesn't work and is unnecessary. Just pass the value:As I assume that
packb()returnsbytes, you could annotate the retur…