On 2019-06-24 09:23, Chris Angelico wrote:> On Mon, Jun 24, 2019 at 6:03
PM Andrew Barnert
On Sunday, June 23, 2019, 10:13:07 PM PDT, Chris Angelico
wrote: The biggest problem with this proposal is the way that, being a syntactic construct, it's going to be non-composable.
# Oops, syntax error with (some_expr as q, some_other_expr as w): pass
I don't understand. Are you suggesting that some_expr could be
something like "2 if cond else pass", so if not cond, this is supposed to be equivalent to "with ( as q, some_other_expr as w):", which is a SyntaxError (at runtime)? If so, that's the same problem as with most other syntactic locations where an expression can go, like the assignment example I gave earlier.
Sorry, I kinda glossed over a lot of details there.
The example that I gave is a SyntaxError, unrelated to the current proposal. To make it work, you have to remove the parens, and use a backslash to continue the line. And every now and then, someone proposes to make the 'with' statement accept the form I gave, because it would be cleaner. It isn't an easy change, because "with expr as name" is a syntactic construct; the "expr as name" part cannot be composed into a larger expression.
The proposed syntax would have the exact same problem:
stuff = [ foo unless True, bar unless False, (quux("spam", "eggs", "sausage", "spam") unless customer_wants("spam")) ]
This particular example would work if you just removed the parens (it doesn't need a backslash to continue the line, since it's inside a list display), but I can pretty much guarantee that people will put parens around one of these sequences and then wonder why on earth it doesn't work.
Well, I suppose it could work with parentheses, but not necessarily in the way you want/expect. If customer_wants("spam") returns False, then (quux("spam", "eggs", "sausage", "spam") unless customer_wants("spam")) could mean ()! (You could say that it doesn't, and if you want that behaviour then you should add a trailing comma.)