[Python-ideas] Re: Use __signature__ in help() and perhaps somewhere else too

2019-11-15 Thread Andrew Barnert via Python-ideas
On Nov 15, 2019, at 16:07, Danilo J. S. Bellini wrote: > > Hi! > > # First simple idea: > > TL;DR: Let's show a inspect.Signature instance to the help messages instead > of just writing its actual "vague" signature [usually (*args, **kwargs)]. But that’s what already happens: >>> import

[Python-ideas] Use __signature__ in help() and perhaps somewhere else too

2019-11-15 Thread Danilo J. S. Bellini
Hi! *# First simple idea:* TL;DR: Let's show a inspect.Signature instance to the help messages instead of just writing its actual "vague" signature [usually (*args, **kwargs)]. Suppose we have a decorator that returns a wrapper: @functools.wraps(func) def wrapper(*args, **kwargs): ... # som

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

2019-11-15 Thread Chris Angelico
On Sat, Nov 16, 2019 at 10:21 AM Andrew Barnert wrote: > > On Nov 15, 2019, at 14:52, Chris Angelico wrote: > > > > On Sat, Nov 16, 2019 at 9:44 AM Oscar Benjamin > > wrote: > >> > >>> On Fri, 15 Nov 2019 at 12:04, Serhiy Storchaka > >>> wrote: > >>> > >>> 15.11.19 12:40, Jonathan Fine пише: >

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

2019-11-15 Thread Oscar Benjamin
On Fri, 15 Nov 2019 at 22:54, Chris Angelico wrote: > > On Sat, Nov 16, 2019 at 9:44 AM Oscar Benjamin > wrote: > > > > On Fri, 15 Nov 2019 at 12:04, Serhiy Storchaka wrote: > > > > > > 15.11.19 12:40, Jonathan Fine пише: > > > > The original poster wanted, inside 'with' context management, to o

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

2019-11-15 Thread Andrew Barnert via Python-ideas
On Nov 15, 2019, at 14:52, Chris Angelico wrote: > > On Sat, Nov 16, 2019 at 9:44 AM Oscar Benjamin > wrote: >> >>> On Fri, 15 Nov 2019 at 12:04, Serhiy Storchaka wrote: >>> >>> 15.11.19 12:40, Jonathan Fine пише: The original poster wanted, inside 'with' context management, to open

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

2019-11-15 Thread Chris Angelico
On Sat, Nov 16, 2019 at 9:44 AM Oscar Benjamin wrote: > > On Fri, 15 Nov 2019 at 12:04, Serhiy Storchaka wrote: > > > > 15.11.19 12:40, Jonathan Fine пише: > > > The original poster wanted, inside 'with' context management, to open > > > several files. Context management is, roughly speaking, def

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

2019-11-15 Thread Oscar Benjamin
On Fri, 15 Nov 2019 at 12:04, Serhiy Storchaka wrote: > > 15.11.19 12:40, Jonathan Fine пише: > > The original poster wanted, inside 'with' context management, to open > > several files. Context management is, roughly speaking, deferred > > execution wrapped in a try ... except statement. > >

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

2019-11-15 Thread Greg Ewing
On 16/11/19 4:30 am, Joao S. O. Bueno wrote: Just add __enter__ and __exit__ to tuples themselves! That wouldn't give the same result, though. E.g. if you're using open(), a failure to open a later file in the list should trigger the __exit__ of earlier ones. But using a tuple, all the files ha

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

2019-11-15 Thread Jonathan Fine
Andrew Barnert wrote: > The advantage of your ExitMap over helper (besides being shorter, and > conceptually simpler) is that it’s never misleading. > [snip] Thank you for this, particular your example (snipped). I agree. But maybe I'm biased. > It still seems like overkill for the case of “how

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

2019-11-15 Thread Andrew Barnert via Python-ideas
On Nov 15, 2019, at 04:37, Jonathan Fine wrote: > > > Serhiy suggests > https://docs.python.org/3/library/contextlib.html#contextlib.ExitStack > >>> with ExitStack() as stack: > >>> files = [stack.enter_context(open(fname)) for fname in filenames] > > A simpler alternative, for the OP's o

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

2019-11-15 Thread Random832
On Fri, Nov 15, 2019, at 10:30, Joao S. O. Bueno wrote: > Just throwing this idea in: what about an approach _not touching_ the > parser or compiler at all? : > Just add __enter__ and __exit__ to tuples themselves! Instead of > repeating "why should we ever do that", we > _do_ that exactly to ent

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

2019-11-15 Thread Joao S. O. Bueno
> I think it could also be done by letting the grammar parse it as a tuple and then having an extra (non-declarative) fixup step. But that obviously makes parsing more complicated to think through, and to document, etc. Just throwing this idea in: what about an approach _not touching_ the parser o

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

2019-11-15 Thread Jonathan Fine
I thank Chris and Serhiy for their helpful comments. I agree with both of you, that a lambda won't be able to give the desired result. However, although flawed the idea was a useful stepping stone for me. Perhaps as "the simplest thing that could possibly work". I thank Serhiy for saying that >>>

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

2019-11-15 Thread Serhiy Storchaka
15.11.19 12:40, Jonathan Fine пише: The original poster wanted, inside 'with' context management, to open several files. Context management is, roughly speaking, deferred execution wrapped in a try ... except statement. In case of open() there is no deferred execution. The resource is ac

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

2019-11-15 Thread Chris Angelico
On Fri, Nov 15, 2019 at 9:41 PM Jonathan Fine wrote: > > Hi All > > The original poster wanted, inside 'with' context management, to open several > files. Context management is, roughly speaking, deferred execution wrapped in > a try ... except statement. > > The lambda construction also pr

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

2019-11-15 Thread Jonathan Fine
Hi All The original poster wanted, inside 'with' context management, to open several files. Context management is, roughly speaking, deferred execution wrapped in a try ... except statement. The lambda construction also provides for deferred execution. Perhaps something like >>> with hel