[Python-Dev] Allow __enter__() methods to skip the with statement body?

2009-02-25 Thread Nick Coghlan
An interesting discrepancy [1] has been noted when comparing contextlib.nested (and contextlib.contextmanager) with the equivalent nested with statements. Specifically, the following examples behave differently if cmB().__enter__() raises an exception which cmA().__exit__() then handles (and

Re: [Python-Dev] Allow __enter__() methods to skip the with statement body?

2009-02-25 Thread Brett Cannon
On Wed, Feb 25, 2009 at 04:24, Nick Coghlan ncogh...@gmail.com wrote: An interesting discrepancy [1] has been noted when comparing contextlib.nested (and contextlib.contextmanager) with the equivalent nested with statements. Specifically, the following examples behave differently if

Re: [Python-Dev] Allow __enter__() methods to skip the with statement body?

2009-02-25 Thread Steven Bethard
On Wed, Feb 25, 2009 at 4:24 AM, Nick Coghlan ncogh...@gmail.com wrote: An interesting discrepancy [1] has been noted when comparing contextlib.nested (and contextlib.contextmanager) with the equivalent nested with statements. Specifically, the following examples behave differently if

Re: [Python-Dev] Allow __enter__() methods to skip the with statement body?

2009-02-25 Thread Nick Coghlan
Steven Bethard wrote: If the problem is just the yield, can't this just be fixed by implementing contextlib.nested() as a class rather than as a @contextmanager decorated generator? Or is this a problem with class based context managers too? It's a problem for class-based context managers as