[Python-Dev] PEP 8: Discourage named lambdas?
Scott David Daniels
Scott.Daniels at Acm.Org
Sat May 3 08:23:59 CEST 2008
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
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-Dev
mailing list