[Python-Dev] PEP 7 and braces { .... } on if (original) (raw)

Barry Warsaw barry at python.org
Tue Jun 6 20:30:04 EDT 2017


On Jun 05, 2017, at 08:41 AM, Serhiy Storchaka wrote:

the example above), and the following code is enough readable:

if (PyErrWarnFormat(PyExcDeprecationWarning, 1, "invalid escape sequence '\%c'", *firstinvalidescape) < 0) { PyDECREF(result); return NULL; }

My rationale for placing the opening brace on a separate line, indented to under the if instead of hanging is that it's easier to miss the opening brace in the example you posted above. Visually I (we?) tend to have a harder time recognizing characters sitting way out to the right.

On Jun 05, 2017, at 08:19 AM, Ethan Furman wrote:

I would format that as:

if (PyErrWarnFormat( PyExcDeprecationWarning, 1, "invalid escape sequence '\%c'", *firstinvalidescape) < 0) { PyDECREF(result); return NULL; }

In this case I'd still indent the opening brace to under the if. The mismatched indentation between the open and close braces is jarring to me.

- having all the arguments on separate lines means - the function and first argument don't get run together - it's easy to pick out the individual arguments

That's fine with me, but so is hanging the arguments, so I'd tend to leave this up to the individual devs.

- having the opening brace on its own line means - a little extra white space to buffer the condition and the body - it's easier to read the function name and then drop down to the body

Agreed with the rationale for the open brace being on a separate line, but did you mean to indent the opening and closing braces to different levels?

Cheers, -Barry



More information about the Python-Dev mailing list