[New-bugs-announce] [issue15045] Make textwrap.dedent() consistent with str.splitlines(True) and str.strip()

Nick Coghlan report at bugs.python.org
Mon Jun 11 15:29:18 CEST 2012


New submission from Nick Coghlan <ncoghlan at gmail.com>:

In working on #13857, I noticed that the current regex based implementation of textwrap.dedent() is limited specifically to ASCII whitespace (tabs and spaces) with Unix line endings (a line containing solely a Windows "\r\n" line ending will be deemed to contain a non-whitespace character, since "\r" isn't recognised by the regex)

The new textwrap.indent() function added in #13857 takes a much simpler approach to whitespace handling: its definition of a "line" is exactly that of "text.splitlines(True)", while its definition of a line that does not consist solely of whitespace is "bool(line.strip())"

As a simple example of how that can make a difference, consider:

>>> "\N{NO-BREAK SPACE}".strip()
''

One way to remedy this would be to replace the regex based implementation of textwrap.dedent with a simpler one written in terms of text.splitlines(True) and line.strip().

----------
components: Library (Lib)
messages: 162617
nosy: ncoghlan
priority: normal
severity: normal
stage: needs patch
status: open
title: Make textwrap.dedent() consistent with str.splitlines(True) and str.strip()
type: enhancement
versions: Python 3.4

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


More information about the New-bugs-announce mailing list