GeezerVison is showing github.com — set object is not JSON serializable with iterable_mode=IM_ANY_ITERABLE · Issue #168 · python-rapidjson/python-rapidjson
set object is not JSON serializable with iterable_mode=IM_ANY_ITERABLE #168Description>>> rapidjson.dumps({1}, iterable_mode=rapidjson.IM_ANY_ITERABLE)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: {1} is not JSON serializable
>>> rapidjson.__version__
'1.8'
Given that documentation states "any iterable will be dumped as a JSON array," I would expect a set object to serialize to an array.
Note, it does appear that creating an iterator object from the set will successfully serialize:
>>> rapidjson.dumps(iter({1}), iterable_mode=rapidjson.IM_ANY_ITERABLE)
'[1]'Reacted by Aziz Khoury and janw Activitylelit commented on Aug 23, 2022 Thank you for the report, I will try to understand and fix the issue. lelit commented on Aug 23, 2022 I'm not sure if/how this should be fixed...
On one hand, I realize that IM_ANY_ITERABLE (that by the way is the default for iterable_mode) suggests that it should slurp anything for which iter(X) works, but under the hood it is actually implemented as PyIter_Check(), and thus it is currently misleading.
On the other hand, I'm reluctant to effectively rectify its implementation, because that could break existing usages: doing that for example breaks three tests, this to mention one.
I will think about this, or wait for some feedback 😜 akhoury commented on Nov 8, 2022 running into this issue as well lelit commented on Nov 8, 2022 I started hacking on this, but got distracted away, sorry. I will try to refocus, as time permits. Reacted by Aziz Khoury and Anna Pekarska NothisIm commented on May 5, 2023 hi @lelit
any updates on this? would be really cool to get this fixed 🙏 lelit commented on May 5, 2023 lelit commented on Oct 16, 2026 First of all, I'm sorry this is taking so long.
I reviewed PR #246, and I'm still unsure whether that is the right move here. I'm flip/flopping between two point of views...
IM_ANY_ITERABLE is too broad: should be deprecated and replaced by IM_ANY_ITERATOR, what it really means now
- Ok, «practicality beats purity», and sets are a rather common and important iterable to be merit a special treatment
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|