WHUI! (was Re: [Python-Dev] Proposal: C API Macro to decref andset to NULL)

Tim Peters tim.peters at gmail.com
Tue Jul 13 17:47:51 CEST 2004

> > This violates the Python C style by putting an assignment in a conditional.

> Where is this documented?  Assignments in conditionals are used widely
> in the C sources, including such places as gcmodule.c, object.c, and
> typeobject.c.

It's not actually part of PEP 7 (the Python C style guidelines).

It was an informal rule in PythonLabs (at least the non-Guido part of
it <wink>), triggered by noting how many subtle bugs in real life
ended up involving an embedded-in-a-conditional assignment.  I don't
run around getting rid of those for their own sake, but if I'm
rewriting a piece of code for other reasons it's a transformation I
routinely make now.  And you can count the number of Python bugs
traced to my C code over the last decade on one finger <wink -- but
avoiding doing multiple things on a single line really helps, and so
does avoiding side effects in the interior of expressions>.

More information about the Python-Dev mailing list