qiemem/PythonExtension

Dicts with non-string keys get serialized wrong

qiemem opened this issue · 2 comments

Some examples:

observer> show py:runresult "{1: 2}"
observer: [["1" 2]]
observer> show py:runresult "{(1,2): 3}"
Extension exception: keys must be a string

While JSON is restricted to string keys, we are not. We need to hijack JSON's dict serialization to turn them into a list of pairs instead.

A current workaround is to just do:

 show py:runresult "{(1,2): 3}.items()"

This is because keys are always strings in JSON. So I think the only way to fix this is to either:

  1. Switch away from JSON
  2. Convert dicts to lists of pairs before serialization