[Python-ideas] Re: `__lcontains__` for letting the other class determine container membership when `__contains__` fails

2019-11-13 Thread Random832
On Tue, Nov 12, 2019, at 20:00, Samuel Muldoon wrote: > > *Currently, the `in` operator (also known as `__contains__`) always > uses the rightmost argument's implementation.* minor bikeshed: I've always considered the "r" in these to mean "reverse", not "right". more serious issue: method pai

[Python-ideas] Using 'with' with extra brackets for nicer indentation

2019-11-13 Thread gabriel . kabbe
Hello everybody, today I tried to open four files simultaneously by writing with ( open(fname1) as f1, open(fname2) as f2, open(fname3) as f3, open(fname4) as f4 ): ... However, this results in a SyntaxError which is caused by the extra brackets. Is there a reason that brack

[Python-ideas] Re: Using 'with' with extra brackets for nicer indentation

2019-11-13 Thread Joao S. O. Bueno
This has being thought, asked, and even agreed as nice thing before, however, it is blocked due to ambiguity on the syntax for some corner cases - and, I may be wrong n that, it would not be possible to do with the current parser (and Python is not shifting to a more complex parser for this featur

[Python-ideas] Re: Using 'with' with extra brackets for nicer indentation

2019-11-13 Thread James Edwards
The syntax error is coming from finding "as" in a place it's unexpected. (Additionally, if you were to drop the `as fn`, you'd get an AttributeError as tuple.__enter__ isn't defined). There's a contextlib helper that you might consider: https://docs.python.org/3/library/contextlib.html#contextlib.

[Python-ideas] Re: Using 'with' with extra brackets for nicer indentation

2019-11-13 Thread Guido van Rossum
I would not recommend ExitStack for this scenario -- it's meant for situations where the cleanup is *dynamic* (see examples in the docs: https://docs.python.org/3/library/contextlib.html#contextlib.ExitStack). On Wed, Nov 13, 2019 at 10:53 AM James Edwards wrote: > The syntax error is coming fro

[Python-ideas] Re: Using 'with' with extra brackets for nicer indentation

2019-11-13 Thread Andrew Barnert via Python-ideas
On Nov 13, 2019, at 10:26, [email protected] wrote: > > Hello everybody, > > today I tried to open four files simultaneously by writing > > with ( >open(fname1) as f1, >open(fname2) as f2, >open(fname3) as f3, >open(fname4) as f4 > ): >... > > However, this results in a

[Python-ideas] Re: Using 'with' with extra brackets for nicer indentation

2019-11-13 Thread MRAB
On 2019-11-13 18:26, [email protected] wrote: Hello everybody, today I tried to open four files simultaneously by writing with ( open(fname1) as f1, open(fname2) as f2, open(fname3) as f3, open(fname4) as f4 ): ... However, this results in a SyntaxError which is ca

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-13 Thread Brett Cannon
Correct, bad typo. :) On Tue, Nov 12, 2019 at 2:31 PM Eric V. Smith wrote: > > *PEP 328 doesn’t seem to mention any of the names detailed below.* >> > > I strongly advise reading PEPs as documentation once their work has > landed. At that point they are mostly historical documents and will not b

[Python-ideas] Re: Using 'with' with extra brackets for nicer indentation

2019-11-13 Thread Eric Fahlgren
On Wed, Nov 13, 2019 at 11:26 AM MRAB wrote: > "with" expression ["as" name] ":" > > but the expression itself can start with a parenthesis, so if it saw a > parenthesis after the "with" it would be ambiguous > I have used 'with' for so long that I was under the impression that the as-targe

[Python-ideas] Re: Using 'with' with extra brackets for nicer indentation

2019-11-13 Thread Chris Angelico
On Thu, Nov 14, 2019 at 8:48 AM Eric Fahlgren wrote: > I have used 'with' for so long that I was under the impression that the > as-target was just a name as in MRAB's simplified syntax above, so imagine my > surprise when I tried putting parentheses around the target and didn't get a > syntax

[Python-ideas] Re: Using 'with' with extra brackets for nicer indentation

2019-11-13 Thread Sebastian Kreft
What Eric Fahlgren wants is basically the deprecated contextlib.nested function, that function should have the right semantics. See https://github.com/python/cpython/blob/2.7/Lib/contextlib.py#L88-L129 On Wed, Nov 13, 2019 at 6:55 PM Chris Angelico wrote: > On Thu, Nov 14, 2019 at 8:48 AM Eric F

[Python-ideas] Re: Using 'with' with extra brackets for nicer indentation

2019-11-13 Thread Eric Fahlgren
On Wed, Nov 13, 2019 at 2:09 PM Sebastian Kreft wrote: > What Eric Fahlgren wants is basically the deprecated contextlib.nested > function, that function should have the right semantics. See > https://github.com/python/cpython/blob/2.7/Lib/contextlib.py#L88-L129 > Oh, no, I don't want it. :) I

[Python-ideas] Re: Using 'with' with extra brackets for nicer indentation

2019-11-13 Thread Greg Ewing
On Nov 13, 2019, at 10:26, [email protected] wrote: with ( open(fname1) as f1, open(fname2) as f2, open(fname3) as f3, open(fname4) as f4 ): Maybe you should be able to do something like with: open(fname1) as f1: open(fname2) as f2: open(fname3)