py_yyjson
py_yyjson copied to clipboard
SystemError when trying to serialize a dictionary with non-string keys
Hi, I ran across this error today which seems like a bug:
$ python -c "import yyjson; yyjson.dumps({'a':'a', 2:2})"
TypeError: bad argument type for built-in operation
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "~/.pyenv/versions/3.11.7/lib/python3.11/site-packages/yyjson/__init__.py", line 71, in dumps
return Document(obj, default=default).dumps()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SystemError: <class 'cyyjson.Document'> returned a result with an exception se
The preferred behavior here would probably be to raise a ValueError with a descriptive message about the dict key not being a string.
This was tested with py_yyjson v4.0.6 from pypi.
Thanks!
The repro case can be further minimized to just python -c "import yyjson; yyjson.dumps({2:2})".
Here's another edge case (surrogates in the dict key): python -c "import yyjson; yyjson.dumps({'\ud83d\ude47': 'foo'})"