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

Paul Moore p.f.moore at gmail.com
Wed May 31 11:23:50 EDT 2017


On 31 May 2017 at 15:11, Victor Stinner <victor.stinner at gmail.com> wrote:

So I would suggest to modify the PEP 7 to always require braces for if.

I would also suggest to require braces on "for(...) { ... }" and "while(...) { ... }". But only if the code has to be modified, not only to update the coding style. Changes which are pure coding style changes should be rejected to avoid conflicts with other pending pull requests and "code churn".

As a practical compromise, I'd argue that if you're changing existing code, you should retain the current style. For new code, always add braces. So, changing

if (func == NULL) return NULL; /* further code */

to

if (func1 == NULL) return NULL; /* further code */

you would leave out the braces. But changing

/* Code using func */

to

if (func == NULL) { return NULL; } /* Code using func */

you include the braces, because it's new code.

I'm not against making the PEP mandate braces, but I don't think it's necessary to resolve the situation you describe as having triggered the suggestion :-)

Paul



More information about the Python-Dev mailing list