Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Terry Reedy
On 10/17/2013 7:35 PM, Nick Coghlan wrote: On 18 Oct 2013 06:59, "Xavier Morel" mailto:catch-...@masklinn.net>> wrote: > > On 2013-10-17, at 22:11 , Ethan Furman wrote: > > > On 10/17/2013 01:03 PM, Terry Reedy wrote: > >> > >> class suppress: > >> def __init__(self, *exceptions): > >>

Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Gregory P. Smith
> Right again. The simplest rule to remember seems to be "don't use yield or > yield-from inside a with-statement". You can relax it by limiting it to > context managers that manage any kind of shared resource, but that is > probably already too subtle: e.g. yielding inside "with open(file) as f" >

Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Greg Ewing
Guido van Rossum wrote: yielding inside "with open(file) as f" seems fine, but yielding inside "with lock" is problematic, since the other side might try to acquire the same lock, and deadlock. So maybe the documentation of a context manager should include whether it's safe to yield inside the

Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Nick Coghlan
On 18 Oct 2013 06:59, "Xavier Morel" wrote: > > On 2013-10-17, at 22:11 , Ethan Furman wrote: > > > On 10/17/2013 01:03 PM, Terry Reedy wrote: > >> > >> class suppress: > >> def __init__(self, *exceptions): > >> self.exceptions = exceptions > >> def __exit__(self, etype, eval, etrace): > >

Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Nick Coghlan
On 18 Oct 2013 09:05, "Guido van Rossum" wrote: > > On Thu, Oct 17, 2013 at 3:51 PM, Oscar Benjamin < oscar.j.benja...@gmail.com> wrote: >> >> On 17 October 2013 20:01, Guido van Rossum wrote: >> > On Thu, Oct 17, 2013 at 11:55 AM, Oscar Benjamin >> > wrote: >> >> >> >> On 17 October 2013 19:40,

Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Guido van Rossum
On Thu, Oct 17, 2013 at 3:51 PM, Oscar Benjamin wrote: > On 17 October 2013 20:01, Guido van Rossum wrote: > > On Thu, Oct 17, 2013 at 11:55 AM, Oscar Benjamin > > wrote: > >> > >> On 17 October 2013 19:40, Xavier Morel wrote: > >> > I think there's already a significant split between context m

Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Oscar Benjamin
On 17 October 2013 20:01, Guido van Rossum wrote: > On Thu, Oct 17, 2013 at 11:55 AM, Oscar Benjamin > wrote: >> >> On 17 October 2013 19:40, Xavier Morel wrote: >> > I think there's already a significant split between context managers >> > which handle the lifecycle of a local resource (file, t

Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Ethan Furman
On 10/17/2013 01:57 PM, Xavier Morel wrote: On 2013-10-17, at 22:11 , Ethan Furman wrote: On 10/17/2013 01:03 PM, Terry Reedy wrote: class suppress: def __init__(self, *exceptions): self.exceptions = exceptions def __exit__(self, etype, eval, etrace): return etype in self.exce

Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Xavier Morel
On 2013-10-17, at 22:11 , Ethan Furman wrote: > On 10/17/2013 01:03 PM, Terry Reedy wrote: >> >> class suppress: >> def __init__(self, *exceptions): >> self.exceptions = exceptions >> def __exit__(self, etype, eval, etrace): >> return etype in self.exceptions > > This fails when etyp

Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Ethan Furman
On 10/17/2013 01:03 PM, Terry Reedy wrote: class suppress: def __init__(self, *exceptions): self.exceptions = exceptions def __exit__(self, etype, eval, etrace): return etype in self.exceptions This fails when etype is a subclass of the exceptions, as mentioned in the original

Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Gregory P. Smith
On Thu, Oct 17, 2013 at 9:06 AM, Barry Warsaw wrote: > On Oct 18, 2013, at 01:26 AM, Nick Coghlan wrote: > > >By contrast, suppress() and redirect_stdout() are the *first* general > >purpose context managers added to contextlib since its incarnation in > >Python 2.5 (although there have been many

Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Stefan Krah
Xavier Morel wrote: > On 2013-10-17, at 20:55 , Oscar Benjamin wrote: > > On 17 October 2013 19:40, Xavier Morel wrote: > >> I think there's already a significant split between context managers > >> which handle the lifecycle of a local resource (file, transaction) and > >> those which purport to

Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Terry Reedy
On 10/17/2013 12:06 PM, Barry Warsaw wrote: On Oct 18, 2013, at 01:26 AM, Nick Coghlan wrote: By contrast, suppress() and redirect_stdout() are the *first* general purpose context managers added to contextlib since its incarnation in Python 2.5 (although there have been many various domain spec

Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Xavier Morel
On 2013-10-17, at 20:55 , Oscar Benjamin wrote: > On 17 October 2013 19:40, Xavier Morel wrote: >> I think there's already a significant split between context managers >> which handle the lifecycle of a local resource (file, transaction) and >> those which purport to locally alter global-ish state

Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Guido van Rossum
On Thu, Oct 17, 2013 at 11:55 AM, Oscar Benjamin wrote: > On 17 October 2013 19:40, Xavier Morel wrote: > > I think there's already a significant split between context managers > > which handle the lifecycle of a local resource (file, transaction) and > > those which purport to locally alter glo

Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Oscar Benjamin
On 17 October 2013 19:40, Xavier Morel wrote: > I think there's already a significant split between context managers > which handle the lifecycle of a local resource (file, transaction) and > those which purport to locally alter global-ish state (cwd, > decimal.localcontext, logging.captureWarning

Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Barry Warsaw
On Oct 17, 2013, at 08:40 PM, Xavier Morel wrote: >I think there's already a significant split between context managers >which handle the lifecycle of a local resource (file, transaction) and >those which purport to locally alter global-ish state (cwd, >decimal.localcontext, logging.captureWarning

Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Xavier Morel
On 2013-10-17, at 18:06 , Barry Warsaw wrote: > On Oct 18, 2013, at 01:26 AM, Nick Coghlan wrote: >> By contrast, suppress() and redirect_stdout() are the *first* general >> purpose context managers added to contextlib since its incarnation in >> Python 2.5 (although there have been many various do

Re: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Glenn Linderman
On 10/17/2013 9:06 AM, Barry Warsaw wrote: There's a fundamental conceptual shift here that's worth exploring more, and which I think was first identified by RDM. Until now, context managers were at their heart (at least IMHO) about managing "resources". A general resource might be an open file

[Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

2013-10-17 Thread Barry Warsaw
On Oct 18, 2013, at 01:26 AM, Nick Coghlan wrote: >By contrast, suppress() and redirect_stdout() are the *first* general >purpose context managers added to contextlib since its incarnation in >Python 2.5 (although there have been many various domain specific >context manager additions elsewhere in