On 23 January 2017 at 22:29, MRAB <pyt...@mrabarnett.plus.com> wrote: > On 2017-01-23 20:09, Nick Timkovich wrote: >> >> Related and probably more common is the need for the line-continuation >> operator for long/multiple context managers with "with". I assume that's >> come up before, but was it also just a low priority rather than any >> technical reason? >> > It has come up before, and there is a technical reason, namely the syntactic > ambiguity when parsing. Not impossible to fix, but probably not worth the > added complexity.
Right, it's the fact parentheses are already allowed there, but mean something quite different: >>> with (1, 2, 3): pass ... Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: __enter__ These days, I'd personally be in favour of changing the parsing of parentheses in that situation, as if we were going to add meaningful context management behaviour to tuples we would have done it by now, and having the name bindings next to their expressions is easier to read than having them all at the end: with (cm1() as a, cm2() as b, cm3() as c): ... Relative to tuples-as-context-managers, such an approach would also avoid reintroducing the old resource management problems that saw contextlib.nested removed and replaced with contextlib.ExitStack. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/