On Mon, Jun 24, 2019 at 6:03 PM Andrew Barnert <[email protected]> wrote:
>
> On Sunday, June 23, 2019, 10:13:07 PM PDT, Chris Angelico <[email protected]>
> 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.
ChrisA
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/NGFOPEENZQMELX4SVVKU2NQNQXEBS3CU/
Code of Conduct: http://python.org/psf/codeofconduct/