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

Antoine Pitrou solipsis at pitrou.net
Thu Oct 13 15:51:10 CEST 2011


On Thu, 13 Oct 2011 15:41:45 +0200
Antoine Pitrou <solipsis at pitrou.net> wrote:

> On Thu, 13 Oct 2011 22:06:00 +1000
> Nick Coghlan <ncoghlan at gmail.com> wrote:
> > Actually, here's an interesting example based on quickly firing up a
> > worker thread:
> > 
> > postdef t = threading.Thread(target=def); t.start()
> > def pointless():
> >     """A pointless worker thread that does nothing except serve as an example"""
> >     print("Starting")
> >     time.sleep(3)
> >     print("Ending")
> 
> I think the problem is still that the syntax isn't nice or obvious.
> Until the syntax is nice and obvious, I don't think there's any point
> adding it.
> (by contrast, decorators *are* nice and obvious: writing "@classmethod"
> before a method was tons better than the previous redundant idiom)

So how about re-using the "lambda" keyword followed by the anonymous
function's parameters (if any)?

x = weakref.ref(target, lambda obj):
    print("{} is being destroyed".format(obj))

t = threading.Thread(target=lambda):
    """A pointless worker thread that does nothing except serve
    as an example"""
    print("Starting")
    time.sleep(3)
    print("Ending")

t.start()






More information about the Python-ideas mailing list