This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author doerwalter
Recipients biloup, doerwalter, eric.smith
Date 2018-06-13.13:00:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1528894802.4.0.947875510639.issue33850@psf.upfronthosting.co.za>
In-reply-to
Content
The problem here is that StreamArray lies about the length of the iterator. This confuses json.encoder._make_iterencode._iterencode_list(), (which is called by json.dump()), because it first does a check for "if not lst" and then assumes in the loop that it will be entered at least once.

(Note that json.dumps() doesn't have that problem, because it calls JSONEncoder.encode() with _one_shot=True which leads to a totally different code path).

We could declare that bug as "don't do that then", but the problem is easily solvable, because we can check whether the loop was entered. The attached patch should do the trick.

An even better approach would IMHO be, that the encoder supports a special flag that enables JSON serialization of generators directly, so it's no longer required to masquerade generators as list
History
Date User Action Args
2018-06-13 13:00:02doerwaltersetrecipients: + doerwalter, eric.smith, biloup
2018-06-13 13:00:02doerwaltersetmessageid: <1528894802.4.0.947875510639.issue33850@psf.upfronthosting.co.za>
2018-06-13 13:00:02doerwalterlinkissue33850 messages
2018-06-13 13:00:02doerwaltercreate