Re: [Python-ideas] Generalized version of contextlib.close

2018-04-02 Thread Nick Coghlan
On 26 March 2018 at 18:35, Roberto Martínez wrote: > @contextmanager > def calling(fn, *args, **kwargs): > try: > yield > finally: > fn(*args, **kwargs) I'd be more amenable to a proposal along these lines (rather than adding a parameter to

Re: [Python-ideas] Generalized version of contextlib.close

2018-04-01 Thread Giampaolo Rodola'
On Mon, Mar 26, 2018 at 10:35 AM, Roberto Martínez < robertomartin...@gmail.com> wrote: > Hi, > > sometimes I need to use contextlib.close but over methods with a different > name, for example stop(), halt(), etc. For those cases I have to write my > own contextlib.close specialized version with

Re: [Python-ideas] Generalized version of contextlib.close

2018-04-01 Thread francismb
On 03/26/2018 10:35 AM, Roberto Martínez wrote: > Hi, > > sometimes I need to use contextlib.close but over methods with a different > name, for example stop(), halt(), etc. For those cases I have to write my > own contextlib.close specialized version with a hard-coded method name. > > I think

[Python-ideas] Generalized version of contextlib.close

2018-03-26 Thread Roberto Martínez
Hi, sometimes I need to use contextlib.close but over methods with a different name, for example stop(), halt(), etc. For those cases I have to write my own contextlib.close specialized version with a hard-coded method name. I think adding a "method" argument to contextlib.close can be very