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

2017-04-23 Thread Terry J. Reedy
Terry J. Reedy added the comment: Thank you Raymond. What I missed before is a) the OP's misnamed EmptyIterator is an iterable (possibly non-empty) but not an iterator, empty or otherwise, and b) a sequence __len__ that lies is just a bug. (So is a iterator that does not yield the contents

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

2017-04-23 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: This looks as a strong argument to me. Thanks Raymond. -- resolution: -> not a bug stage: patch review -> resolved status: open -> closed ___ Python tracker

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

2017-04-23 Thread Raymond Hettinger
Raymond Hettinger added the comment: Per PEP-8, the Python preferred-style is, "For sequences, (strings, lists, tuples), use the fact that empty sequences are false." Yes: if not seq: if seq: No: if len(seq): if not len(seq): The Python libraries are not obliged to

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

2017-04-22 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- pull_requests: +1370 ___ Python tracker ___ ___

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

2017-04-22 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: > I am surprised that dumping to a string and to a file give different answers. This is a difference between Python and C implementations. An iterable with fake __len__ looks breaking the invariants, but if a collection with overridden __bool__() is

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

2016-07-29 Thread ppperry
Changes by ppperry : -- title: Empty iterator is rendered as a single bracket ] when using json's iterencode -> Empty iterator with fake __len__ is rendered as a single bracket ] when using json's iterencode ___ Python tracker