[Python-Dev] exec/with thunk-handling proposal
Aahz
aahz@pythoncraft.com
Mon, 3 Feb 2003 10:21:25 -0500
On Mon, Feb 03, 2003, holger krekel wrote:
>
> def __enter__(self):
> "before suite start"
>
> def __except__(self, type, value, tb):
> "swallow given exception, reraise if neccessary"
>
> def __leave__(self):
> """upon suite finish (not called if __except__
> exists and an exception happened)
> """
No, __leave__/__exit__ should always be called regardless of whether an
exception hits. That's the whole point of this proposal, IMO.
> One remark (mainly to Michael as he does that other
> patch) about the hook-name __leave__ versus __exit__.
> we may want to eventually allow 'yield' within the
> thunk and then '__exit__' would be misleading. Here is
> the use case:
>
> exec self.mylock: # would lock/unlock on entering/leaving
> # the generator
> ...
> for whatever in something:
> yield whatever
> ...
I'm thinking that this is *way* too complex. If you want something like
that, code it like this:
for whatever in something:
exec self.mylock:
new_whatever = process(whatever)
yield new_whatever
--
Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/
"Argue for your limitations, and sure enough they're yours." --Richard Bach