[Python-Dev] PEP 8: Discourage named lambdas? (original) (raw)

Mike Klaas mike.klaas at gmail.com
Sat May 3 08:32:40 CEST 2008


On 2-May-08, at 11:23 PM, Scott David Daniels wrote:

Mike Klaas wrote:

... A common pattern for me is to replace an instances method with a lambda to add monitoring hooks or disable certain functionality: inst.getfoo = lambda: FakeFoo() This is not replacable in one line with a def (or without locals() detritius). Assuming this is good style, it seems odd that inst.getfoo = lambda: FakeFoo() is acceptible style, but getfoo = lambda: FakeFoo() But surely, none of these are great style, and in fact the lambda lures you into using it. I'd propose a far better use is: inst.getfoo = FakeFoo or getfoo = FakeFoo

Sorry, that was a bad example. It is obviously silly if the return
value of the function is callable.

-Mike



More information about the Python-Dev mailing list