This is fairly similar to a recent thread suggesting an "or raise" construct ("x = f() or raise ValueError" as a shortcut for "x = f(); if not x: raise ValueError"). I suggested that "raise" be made a value-less expression, so that "x = f() or raise ..." can be intepreted normally. As a side effect, this would make lambdas slightly more powerful too.
Having "return" and "break" as value-less expressions would be nice too. The interaction with nested loops in generators would be the natural one, without any generator-specific syntax:
((x, y) if stay_in_inner(x, y) else break for x in X for y in Y)
is the same as
for x in X:
for y in Y:
if stay_in_inner(x, y):
yield x, y
else:
break
or, with break-expression everywhere, as a separate generator:
for x in X:
for y in Y:
(yield x, y) if stay_in_inner(x, y) else break
whereas
((x, y) if stay_in_gen(x, y) else return for x in X for y in Y)
is the same as
for x in X:
for y in Y:
if stay_in_gen(x, y):
yield x, y
else:
return
or
for x in X:
for y in Y:
(yield x, y) if stay_in_gen(x, y) else return
i.e. the intepretation of a genexp is still to take the nested "for"s and "if"s after the leading expression, add suitable colons, newlines and indentation, and insert the leading expression at the end.
Antony