[Python-ideas] Long Live PEP 3150 (was: Re: Statement local functions and classes (aka PEP 3150 is dead, say 'Hi!' to PEP 403))

Scott Dial scott+python-ideas at scottdial.com
Tue Oct 18 14:53:22 CEST 2011


On 10/17/2011 9:18 AM, Nick Coghlan wrote:
> 1. Adopt a syntax that still names the functions, but uses those names
> to allow forward references to functions that are defined later in a
> private indented suite (this is the route I've taken in PEP 3150).

It may be that I have spent so much time using Twisted, but this seems
like the only viable solution given my need to define callbacks
simultaneously with an errback. That is:

  d = getDeferredFromSomewhere()
  d.addCallbacks(callback, errback)

Being only able to name a single anonymous function is significantly
less useful (perhaps to the point of useless) to anyone writing Twisted
Deferred-style code. (BTW, you cannot split that into two statements to
weasel around the "given" limitation).

Personally, I never noticed that this "style" was awkward. If I was
writing C, then I would have to put those functions into the file-scope
and, while there is no ordering restriction there, I always put them
above all of the functions I used them in. So when I came to Python, I
just kept with that style except that I don't have to elevate them to
the module-scope if a closure is useful (often it is!).

Usually my callbacks/errbacks are non-trivial enough that I would not
want to put them inline with executable statements -- I usually pull
them to the top of whatever scope I am defining them and live with the
out-of-order-ness. However, I could see how hanging them off the bottom
in an indented scope might be more readable.

-- 
Scott Dial
scott at scottdial.com



More information about the Python-ideas mailing list