[issue33850] Json.dump() bug when using generator

2018-06-13 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: This is a duplicate of issue27613. -- nosy: +serhiy.storchaka resolution: -> duplicate status: open -> closed superseder: -> Empty iterator with fake __len__ is rendered as a single bracket ] when using json's iterencode _

[issue33850] Json.dump() bug when using generator

2018-06-13 Thread Walter Dörwald
Walter Dörwald added the comment: 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 w

[issue33850] Json.dump() bug when using generator

2018-06-13 Thread Eric V. Smith
Eric V. Smith added the comment: You should ask your question on this mailing list: https://mail.python.org/mailman/listinfo/python-list The bug tracker is not a place for asking how to use Python. If you actually find a bug in Python, you can re-open this issue. I do not believe that what

[issue33850] Json.dump() bug when using generator

2018-06-13 Thread Clément Boyer
New submission from Clément Boyer : I use a class to write easily json when having generator. ```python class StreamArray(list): def __init__(self, generator): super().__init__() self.generator = generator def __iter__(self): return self.generator def __len__(s