[Python-Dev] conditional expressions - add parens? (original) (raw)
Jim Jewett jimjjewett at gmail.com
Mon Mar 6 21:15:30 CET 2006
- Previous message: [Python-Dev] conditional expressions - add parens?
- Next message: [Python-Dev] conditional expressions - add parens?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 3/6/06, Thomas Wouters <thomas at python.org> wrote:
On 3/6/06, Jim Jewett <jimjjewett at gmail.com> wrote:
> level = 0 if "absoluteimport" 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 > backtracking.
> I think that adding parentheses would help ...
> level = (0 if "absoluteimport" 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 would prefer that the grammar enforce it, but putting it in PEP 8 would be a half-way measure.
I can't imagine an expression small enough that the parentheses really hurt.
var = t if c else f
var = (t if c else f)
In PEP 8, I would even go so far as to recommend parentheses around the three sub-expressions if they contain any internal whitespace, but I don't think the grammar should enforce that.
(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 :->
Yah, that sounds uncontroversial. :D
-jJ
- Previous message: [Python-Dev] conditional expressions - add parens?
- Next message: [Python-Dev] conditional expressions - add parens?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]