[Python-ideas] yield statements (was relaxing keyword usage restrictions)

Nick Coghlan ncoghlan at gmail.com
Sun Sep 11 03:06:51 CEST 2011


On Sun, Sep 11, 2011 at 2:39 AM, Guido van Rossum <guido at python.org> wrote:
> On Sat, Sep 10, 2011 at 9:09 AM, Stefan Behnel <stefan_ml at behnel.de> wrote:
>> (And, BTW, I agree that the yield should always be in parentheses, but I
>> guess it's too late to change that before Py4.)
>
> You can make that a personal style today. And you could lobby for
> inclusion in PEP 8 (though personally I don't care either way).

As the examples in the PEP suggest, the "no parens" usage was for
simple evolutions from the pre-existing yield statement syntax:

  yield None =>
    x = yield
  yield 42 =>
    x = yield 42
  yield y =>
    x = yield y

For simple cases like that, the parens would be redundant visual
clutter (similar to the ill-advised practice of including redundant
parens in if statements: "if (expr):").

Beyond those simple cases, I don't think there needs to be a yield
specific recommendation - the general guidelines to use parentheses
and named subexpressions to improve readability should cover it.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list