[Python-Dev] Update PEP 7 to require curly braces in C
David Malcolm
dmalcolm at redhat.com
Tue Jan 19 10:36:56 EST 2016
On Mon, 2016-01-18 at 19:18 -0500, Terry Reedy wrote:
> On 1/18/2016 6:20 PM, Brett Cannon wrote:
> >
> >
> > On Sun, 17 Jan 2016 at 11:10 Brett Cannon <brett at python.org
> > <mailto:brett at python.org>> wrote:
> >
> > While doing a review of http://bugs.python.org/review/26129/ I asked
> > to have curly braces put around all `if` statement bodies. Serhiy
> > pointed out that PEP 7 says curly braces are optional:
> > https://www.python.org/dev/peps/pep-0007/#id5. I would like to
> > change that.
> >
> > My argument is to require them to prevent bugs like the one Apple
> > made with OpenSSL about two years ago:
> > https://www.imperialviolet.org/2014/02/22/applebug.html. Skipping
> > the curly braces is purely an aesthetic thing while leaving them out
> > can lead to actual bugs.
> >
> > Anyone object if I update PEP 7 to remove the optionality of curly
> > braces in PEP 7?
> >
> >
> > Currently this thread stands at:
> >
> > +1
> > Brett
> > Ethan
> > Robert
> > Georg
> > Nick
> > Maciej Szulik
> > +0
> > Guido
> > -0
> > Serhiy
> > MAL
> > -1
> > Victor (maybe; didn't specifically vote)
> > Larry
> > Stefan
>
> Though I don't write C anymore, I occasionally read our C sources. I
> dislike mixed bracketing in a multiple clause if/else statement, and
> would strongly recommend against that. On the other hand, to my
> Python-trained eye, brackets for one line clauses are just noise. +-0.
>
> If coverity's scan does not flag the sort of misleading bug bait
> formatting that at least partly prompted this thread
>
> if (a):
> b;
> c;
>
> then I think we should find or write something that does and run it over
> existing code as well as patches.
FWIW, for the forthcoming gcc 6, I've implemented a new
-Wmisleading-indentation warning that catches this. It's currently
enabled by -Wall:
sslKeyExchange.c: In function 'SSLVerifySignedServerKeyExchange':
sslKeyExchange.c:631:8: warning: statement is indented as if it were guarded by... [-Wmisleading-indentation]
goto fail;
^~~~
sslKeyExchange.c:629:4: note: ...this 'if' clause, but it is not
if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
^~
(not that I've had time for core Python development lately, but FWIW in
gcc-python-plugin I mandate braces for single-statement clauses).
Dave
More information about the Python-Dev
mailing list