[Python-ideas] ScopeGuardStatement/Defer Proposal
ncoghlan at gmail.com
Sat Feb 18 16:30:58 CET 2012
On Sat, Feb 18, 2012 at 8:16 AM, Nathan Rice
<nathan.alexander.rice at gmail.com> wrote:
> I just wanted to chime in on this, because I understand the use cases
> and benefits of this but the code is very semantically opaque and
> imperative. I also feel like a lot of C programming concepts and
> semantics have leaked into the design. Additionally, I feel that
> there are some benefits to taking a step back and looking at this
> problem as part of a bigger picture.
So... context managers are not a good fit for general event handling. Correct.
Given that I agree with your basic point, I'm not sure what the rest
of that had to do with anything, unless you heard the word "callback"
and immediately assumed I was talking about general event handling
rather than Go defer'ed style cleanup APIs (along with a replacement
for the bug-prone, irredeemably flawed contextlib.nested API).
I'm not - what I'm planning would be a terrible API for general event
handling. Fortunately, it's just a replacement for contextlib.nested()
as a tool for programmatic management of context managers. If you want
nice clean callbacks for general event handling, Python doesn't
currently provide that. (We certainly don't have anything that gets
remotely close to the elegance of Ruby's blocks for that style of
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas