There is another problem with running dedent on docstrings, I believe: a <a href="http://www.python.org/dev/peps/pep-0257/">PEP 257</a> compliant docstring with a summary line won't dedent at all, since the first line lacks indentation.<div>

<br></div><div>If you wanted to automatically clean docstrings, I think you would want to use the trim(docstring) function from PEP 257, rather than dedent. But I'm guessing there was a reason this has not been done before.</div>

<div><div><br><div class="gmail_quote">On Mon, Jul 1, 2013 at 5:05 AM, Nick Coghlan <span dir="ltr"><<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div class="im">On 1 July 2013 11:57, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div>On Sun, Jun 30, 2013 at 6:47 PM, Nick Coghlan <<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>> wrote:<br>
> On 1 July 2013 11:09, Steven D'Aprano <<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>> wrote:<br>
>> but in either case, I think the choice of --- as delimiter is ugly and<br>
>> arbitrary, and very likely is ambiguous (currently, x = ---1 is legal code).<br>
>> Similar suggestions to this have been made many times before, you should<br>
>> search the archives:<br>
>><br>
>> <a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
><br>
> I'm still partial to the idea of offering textwrap.indent() and<br>
> textwrap.dedent() as string methods.<br>
><br>
> 1. You could add a ".dedent()" at the end of a triple quoted string<br>
> for this kind of problem. For a lot of code, the runtime cost isn't an<br>
> issue.<br>
> 2. A JIT would definitely be able to avoid recalculating the result every time<br>
> 3. Even CPython may eventually gain constant folding for that kind of<br>
> method applied directly to a string literal<br>
> 4. I dedent and indent long strings more often than I capitalize,<br>
> center, tab expand, or perform various other operations which already<br>
> grace the str type as methods.<br>
<br>
</div></div>That's a compelling argument. Let's do it. (Assuming the definition of<br>
exactly how to indent or dedent is not up for discussion -- if there<br>
are good reasons to disagree with textwrap now's the time to bring it<br>
up.)<br></blockquote><div><br></div></div><div>The only slight quirk that occurred to me is that if dedent is a method, people will probably want to use them with docstrings, and the compiler currently doesn't allow that.<br>


<br></div><div>There are then two options for changing the compiler (if we decide we want to allow for "neat" docstrings):<br><br></div><div>1. Implicitly call dedent on docstrings at compilation time (feasible with dedent as a method).<br>


</div><div>2. Allow method calls on docstrings without breaking docstring detection<br><br></div><div>It's technically a separate question from the decision on whether or not to add the methods, but I figured it was worth bringing up. Touching the methods of a builtin *and* possibly the compiler behaviour as well is likely enough to nudge the idea into PEP territory.<br>


<br></div><div>Cheers,<br>Nick.<br clear="all"></div></div><div class="im"><br>-- <br>Nick Coghlan   |   <a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>   |   Brisbane, Australia
</div></div></div>
<br>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
<br></blockquote></div><br></div></div>