[issue27613] Empty iterator is rendered as a single bracket ] when using json's iterencode

R. David Murray report at bugs.python.org
Mon Jul 25 09:48:42 EDT 2016


R. David Murray added the comment:

If you break the invariants (in this case: a list has an accurate len) code that expects lists is only going to work by accident.

What you really want to do is define your own json encoder for your type.  If that isn't possible for a streamed sequence of undefined length, then enhancing json's extension machinery to allow it would be a good feature request.

That said, could json's ability to handle this be improved?  Possibly.  I think we would accept a patch if it doesn't make the code more complicated.  Ideally handling certain cases as "don't care" makes the code simpler, but that may or may not be the case here.  Or it may come out as a consequence of the enhancement.

----------
nosy: +r.david.murray

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27613>
_______________________________________


More information about the Python-bugs-list mailing list