[issue15510] textwrap.wrap('') returns empty list

R. David Murray report at bugs.python.org
Sat Aug 4 21:50:13 CEST 2012


R. David Murray added the comment:

FTR I agree with Antoine that returning the empty list is the more logical behavior here.  Wrap is turning a string into a list of lines...if there is no content, the list of lines *should* be empty, IMO.  That is what I would expect, so for me the empty list follows the principle of least surprise here.  Consider, for example, the fact that [] is False, while [''] is True.  I consider that definitive in favor of returning an empty list when there is no content to wrap, even ignoring the backward compatibility issue.

The issue of preserving whitespace-only is fuzzier, but given that it is fuzzy I also am inclined to leave the current behavior alone (and document it properly).  As Antoine said, there is no point in preserving whitespace unless it is preserving indentation, and if there is nothing but whitespace there is nothing to be indented.

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

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


More information about the Python-bugs-list mailing list