[Python-Dev] conditional expressions - add parens?

Thomas Wouters thomas at python.org
Mon Mar 6 20:16:42 CET 2006


On 3/6/06, Jim Jewett <jimjjewett at gmail.com> wrote:

> From a recent checkin --
>
>     level = 0 if "absolute_import" in self.futures else -1
>
> Mentally, I can't help parsing that as "level = 0" plus comments that turn
> out to be code that triggers backracking.
>
> When the expressions (particularly the true case) are longer, it gets even
> worse.
>
> I think that adding parentheses would help, by at least signalling that
> the logic is longer than just the next (single) expression.
>
>     level = (0 if "absolute_import" in self.futures else -1)
>

I'm not sure, are you suggesting the grammar/parser enforces it that way, or
that it should be in PEP-8?

(I still can't help but go 'yecchh' whenever I see the code. It looks like
Perl's 'expr if expr' form, but it behaves quite different. Right now,
removing if/else expressions still looks like the best solution, to me :->
But gauging reactions (my own and others) to the actual if-expr in use is
the main reason I added those couple of lines to the compiler package.)

--
Thomas Wouters <thomas at python.org>

Hi! I'm a .signature virus! copy me into your .signature file to help me
spread!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20060306/48338b2a/attachment.html 


More information about the Python-Dev mailing list