[Python-ideas] Multi-line comment blocks.

Devin Jeanpierre jeanpierreda at gmail.com
Sat Jun 16 05:48:29 CEST 2012


On Fri, Jun 15, 2012 at 11:26 PM, Bruce Leban <bruce at leapyear.org> wrote:
> For commenting out part of a line I think best practice is duplicating the
> entire line as a comment and editing it directly. That handles scenarios
> that inline comments don't and more importantly ensures reverting is error
> free.

I suppose so. So far I've done pretty much exactly what I wrote, and
used the undo buffer for safety.

There are also things like commenting out values inside lists and
such, but these are much less common for me. Like, definitely inline
comments are more flexible than EOL comments, but finding compelling
use-cases is kinda hard. There's only a bunch of minor special cases
and annoyances, as far as I can see.

>> Python tool world seems to think that strings that aren't inside an
>> expression are "docstrings", not comments, and you have to be careful
>> to avoid being misinterpreted by your tools, which is unfortunate.
>
> Agreed. But even if multiline/inline comments were added you'd still have
> that problem, right?

I don't see why this problem would exist for comments. Comments do not
have a (common) culture or behaviour of meaning anything else other
than comments, whereas triple-quoted strings have three purposes:

- Actual string objects
- Docstrings
- Comments

Multiline comments would need a lot of time to accumulate that many
orthogonal uses, and one would hope that they never do.

Aside from that, most of these sorts of tools manipulate code either
after parsing or after executing, and by then all comments have been
discarded. They wouldn't even see multiline comments.

Although, it's worth mentioning that doctest is an interesting
exception to all this: it uses regexps to parse out comments, which
are used as directives for the test runner. However, doctest only
touches code that is explicitly meant to be touched by doctest, and
that code generally doesn't need comments at all.

-- Devin



More information about the Python-ideas mailing list