qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: John Snow <jsnow@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-block@nongnu.org,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	qemu-devel@nongnu.org, "Max Reitz" <mreitz@redhat.com>,
	armbru@redhat.com
Subject: Re: [PATCH v7 06/10] iotests: limit line length to 79 chars
Date: Thu, 5 Mar 2020 13:25:43 -0500	[thread overview]
Message-ID: <d9500e3c-48d4-8ab2-51c7-9a914dd8ec49@redhat.com> (raw)
In-Reply-To: <20200305115548.GA5363@linux.fritz.box>



On 3/5/20 6:55 AM, Kevin Wolf wrote:
> Am 05.03.2020 um 00:14 hat John Snow geschrieben:
>>
>>
>> On 3/4/20 4:58 PM, Philippe Mathieu-Daudé wrote:
> 
> Adding back the context:
> 
>> -        sys.stderr.write('qemu-img received signal %i: %s\n' % (-exitcode, ' '.join(qemu_img_args + list(args))))
>> +        sys.stderr.write('qemu-img received signal %i: %s\n' % (
>> +            -exitcode, ' '.join(qemu_img_args + list(args))))
> 
>>> Do we want to indent Python like C and align argument below opening
>>> parenthesis? Except when using sys.stderr.write() you seem to do it.
>>
>> This isn't an argument to write, it's an argument to the format string,
>> so I will say "no."
> 
> The argument to write() is an expression. This expression contains the %
> operator with both of its operands. It's still fully within the
> parentheses of write(), so I think Philippe's question is valid.
> 
>> For *where* I've placed the line break, this is the correct indentation.
>> emacs's python mode will settle on this indent, too.
>>
>> https://python.org/dev/peps/pep-0008/#indentation
> 
> The PEP-8 examples are not nested, so it's not completely clear. I
> wonder if hanging indents wouldn't actually mean the following because
> if you line wrap an argument list (which contains the whole %
> expression), you're supposed to have nothing else on the line of the
> opening parenthesis:
> 
>     sys.stderr.write(
>         'qemu-img received signal %i: %s\n'
>         % (-exitcode, ' '.join(qemu_img_args + list(args))))
> 

This is fine too.

> But anyway, I think the question is more whether we want to use hanging
> indents at all (or at least if we want to use it even in cases where the
> opening parenthesis isn't already at like 70 characters) when we're
> avoiding it in our C coding style.
> 
> There's no technical answer to this, it's a question of our preferences.
> 

Maybe it is ambiguous. Long lines are just ugly everywhere.

>> (If anyone quotes Guido's belittling comment in this email, I will
>> become cross.)
>>
>>
>> But there are other places to put the line break. This is also
>> technically valid:
>>
>> sys.stderr.write('qemu-img received signal %i: %s\n'
>>                  % (-exitcode, ' '.join(qemu_img_args + list(args))))
>>
>> And so is this:
>>
>>     sys.stderr.write('qemu-img received signal %i: %s\n' %
>>                      (-exitcode, ' '.join(qemu_img_args + list(args))))
> 
> PEP-8 suggests the former, but allows both styles:
> 
> https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator
> 

So in summary:

- Avoid nested hanging indents from format operators
- Use a line break before the % format operator.
- OPTIONALLY(?), use a hanging indent for the entire format string to
reduce nesting depth.


e.g., either this form:
(using a line break before the binary operator and nesting to the
argument level)

write('hello %s'
      % (world,))


or optionally this form if it buys you a little more room:
(using a hanging indent of 4 spaces and nesting arguments at that level)

write(
    'hello %s'
    % ('world',))


but not ever this form:
(Using a hanging indent of 4 spaces from the opening paren of the format
operand)

write('hello %s' % (
    'world',))



yea/nea?

(Kevin, Philippe, Markus, Max)

>> (And so would be any other number of rewrites to use format codes,
>> f-strings, or temporary variables to otherwise reduce the length of the
>> line.)
>>
>> I will reluctantly admit that wrapping to 79 columns is useful in some
>> contexts. The beauty of line continuations is something I have little
>> desire to litigate, though.
>>
>> If there's some consensus on the true and beautiful way to do it, I will
>> oblige -- but the thought of spinning more iterations until we find a
>> color swatch we like is an unpleasant one.
> 
> I'll accept any colour for the bikeshed, as long as it's green. ;-)
> 
> Kevin
> 



  reply	other threads:[~2020-03-05 18:26 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-04 21:38 [PATCH v7 00/10] iotests: use python logging John Snow
2020-03-04 21:38 ` [PATCH v7 01/10] iotests: do a light delinting John Snow
2020-03-04 21:45   ` Philippe Mathieu-Daudé
2020-03-04 22:43     ` John Snow
2020-03-04 21:38 ` [PATCH v7 02/10] iotests: don't use 'format' for drive_add John Snow
2020-03-04 21:38 ` [PATCH v7 03/10] iotests: ignore import warnings from pylint John Snow
2020-03-04 21:38 ` [PATCH v7 04/10] iotests: replace mutable list default args John Snow
2020-03-04 21:59   ` Philippe Mathieu-Daudé
2020-03-04 21:38 ` [PATCH v7 05/10] iotests: add pylintrc file John Snow
2020-03-04 21:38 ` [PATCH v7 06/10] iotests: limit line length to 79 chars John Snow
2020-03-04 21:58   ` Philippe Mathieu-Daudé
2020-03-04 23:14     ` John Snow
2020-03-05 11:55       ` Kevin Wolf
2020-03-05 18:25         ` John Snow [this message]
2020-03-06 10:14           ` Kevin Wolf
2020-03-06 18:34             ` John Snow
2020-03-07  6:36             ` Markus Armbruster
2020-03-04 21:38 ` [PATCH v7 07/10] iotests: add script_initialize John Snow
2020-03-04 21:38 ` [PATCH v7 08/10] iotest 258: use script_main John Snow
2020-03-04 21:38 ` [PATCH v7 09/10] iotests: Mark verify functions as private John Snow
2020-03-04 21:47   ` Philippe Mathieu-Daudé
2020-03-04 21:38 ` [PATCH v7 10/10] iotests: use python logging for iotests.log() John Snow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d9500e3c-48d4-8ab2-51c7-9a914dd8ec49@redhat.com \
    --to=jsnow@redhat.com \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).