[Python-Dev] PEP 343 - multiple context managers in one statement (original) (raw)
Paul Moore p.f.moore at gmail.com
Wed Oct 26 14:59:34 CEST 2005
- Previous message: [Python-Dev] PEP 343 - multiple context managers in one statement
- Next message: [Python-Dev] Divorcing str and unicode (no more implicit conversions).
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 10/25/05, Nick Coghlan <ncoghlan at gmail.com> wrote:
Paul Moore wrote: [...] > Has the option of letting the with statement admit multiple context > managers been considered (and presumably rejected)? [...] Not rejected - deliberately left as a future option (this is the reason why the RHS of an as clause has to be parenthesised if you want tuple unpacking).
Thanks. I now see that note in the PEP - apologies for missing it in the first instance.
[...]
The issue with that implementation is that the semantics are wrong - it doesn't actually mirror nested with statements. If one of the later enter methods, or one of the first-executed exit methods throws an exception, there are a lot of exit methods that get skipped.
Getting it right is more complicated (and this probably still has mistakes):
Bah. You're right, of course (about it being more complicated - I can't see any mistakes :-))
I'd argue that precisely because a naive approach gets it wrong, having your version as an example in the PEP (and possibly the documentation, much like the itertools module has a recipes section) is that much more useful.
Anyway, thanks for the help. Paul.
- Previous message: [Python-Dev] PEP 343 - multiple context managers in one statement
- Next message: [Python-Dev] Divorcing str and unicode (no more implicit conversions).
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]