textwrap.dedent() drops tabs - bug or feature?
Steven Bethard
steven.bethard at gmail.com
Sat Nov 19 14:07:09 EST 2005
Peter Hansen wrote:
> Steven Bethard wrote:
>
>> Note that even though the tabs are internal, they are still removed by
>> textwrap.dedent(). The documentation[1] says:
>
> ...
>
>> So it looks to me like even if this is a "feature" it is undocumented.
>> I'm planning on filing a bug report, but I wanted to check here first
>> in case I'm just smoking something.
>
> While I wouldn't say it's obvious, I believe it is (indirectly?)
> documented and deliberate.
>
> Search for this in the docs:
> """
> expand_tabs
> (default: True) If true, then all tab characters in text will be
> expanded to spaces using the expandtabs() method of text.
> """
Thanks for double-checking this for me. I looked at expand_tabs, and
it's part of the definition of the TextWrapper class, which is not
actually used by textwrap.dedent(). So I think the textwrap.dedent()
expanding-of-tabs behavior is still basically undocumented.
I looked at the source code, and the culprit is the first line of the
function definition:
lines = text.expandtabs().split('\n')
I filed a bug_ report, but left the Category unassigned so that someone
else can decide whether it's a doc bug or a code bug.
STeVe
.. _bug: http://python.org/sf/1361643
More information about the Python-list
mailing list