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

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to