This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nharold
Recipients bignose, docs@python, nharold
Date 2016-05-26.16:58:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1464281910.68.0.147653695421.issue27043@psf.upfronthosting.co.za>
In-reply-to
Content
Here's my shot at a revision (corresponding patch attached):

   Clean up indentation from docstrings that are indented to line up with blocks
   of code.  All leading whitespace is removed from the first line.  Any leading
   whitespace that can be uniformly removed from the second line onwards is
   removed.  Empty lines at the beginning and end are subsequently removed.  Also,
   all tabs are expanded to spaces.

This version also makes it explicit that nothing happens to trailing whitespace, should a line happen to have any.  This actually seems to be a difference between this function and the sample implementation in the PEP.

One odd side effect of that difference is that a line consisting only of whitespace may actually not be removed from the beginning or end of the string, if the preceding whitespace removals aren't sufficient to leave the line completely empty.  For instance:

>>> inspect.cleandoc('   A \n  B \n   \n  ')
'A \nB \n '

Two spaces are removed from each of the second, third, and fourth lines.  The fourth line is then empty and is removed; the third line still contains one space and is kept.

On the other hand, as defined in the PEP, the extra space on the third line is removed as trailing whitespace, so that the third line is then removed entirely:

>>> trim('   A \n  B \n   \n  ')
'A\nB'

Most likely this difference rarely affects anything.  In any case, mentioning it here because it influenced exactly how I revised the docs.
History
Date User Action Args
2016-05-26 16:58:30nharoldsetrecipients: + nharold, docs@python, bignose
2016-05-26 16:58:30nharoldsetmessageid: <1464281910.68.0.147653695421.issue27043@psf.upfronthosting.co.za>
2016-05-26 16:58:30nharoldlinkissue27043 messages
2016-05-26 16:58:30nharoldcreate