[Python-Dev] PEP 8: Discourage named lambdas?
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.get_foo = 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.get_foo = lambda: FakeFoo()
>> is acceptible style, but
>> get_foo = 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.get_foo = FakeFoo
> or
> get_foo = 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