[Python-ideas] Idea for new multi-line triple quote literal

Steven D'Aprano steve at pearwood.info
Mon Jul 1 15:11:39 CEST 2013


On 01/07/13 22:44, Nick Coghlan wrote:
> On 1 Jul 2013 22:39, "Daniel Robinson" <gottagetmac at gmail.com> wrote:
>>
>> There is another problem with running dedent on docstrings, I believe: a
> PEP 257 compliant docstring with a summary line won't dedent at all, since
> the first line lacks indentation.
>>
>> 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.
>
> I did think of that, and considered the fact existing docstrings would
> generally be left alone to be a feature rather than a bug.

+1

There's little reason to manually call dedent on a docstring, since pydoc will reformat it for display:


py> def factory():
...                     def inner():
...                                     """Doc string.
...
...                                     Note the indentation.
...                                     """
...                     return inner
...
py> help(factory())

Help on function inner in module __main__:

inner()
     Doc string.

     Note the indentation.




-- 
Steven


More information about the Python-ideas mailing list