[issue27613] Empty iterator with fake __len__ is rendered as a single bracket ] when using json's iterencode
Raymond Hettinger
report at bugs.python.org
Sun Apr 23 12:31:20 EDT 2017
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 defend themselves against non-sensical types (i.e. defining an empty iterator as a subclass of list and returning a non-zero len).
I recommend leaving the code as-is and closing a "not a bug". In a way, this report is no more interesting than observing that a __hash__ that returns a random value on each call doesn't work well in a dictionary.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27613>
_______________________________________
More information about the Python-bugs-list
mailing list