lambda *args, **kwargs: None
According to PEP8, you should "Always use a def statement instead of an assignment statement that binds a lambda expression directly to a name." So, one thing I would change is:
def blank_fn(*args, **kwargs): pass
However, I think a more pythonic way to do this is:
def perform_task(callback=None): print 'doing stuff' if callback is not None: callback('x', 'y', z='z')
There shouldn't be any need to call a function that does nothing. Truth value testing is cheaper than function calling.
def do_nothing(*args, **kwargs): passdef do_something(arg, callback=do_nothing): a = 1 + 2 callback('z', z='z')def do_something_else(arg, callback=None): a = 1 + 2 if callback is not None: callback('z', z='z')%timeit do_something(3)1000000 loops, best of 3: 644 ns per loop%timeit do_something_else(3)1000000 loops, best of 3: 292 ns per loop
I think the previous answer is superior, as it provides a better way to accomplish what the OP wanted to do.
However there may arguably be circumstances when you want a noop function when testing, or if you are monkey patching something.
So to answer the OP Question as asked, you can use Mock:
In [1]: from mock import MockIn [2]: blank_fn = Mock(return_value=None)In [3]: blank_fn()In [4]: blank_fn("foo")In [5]: blank_fn(bar="foo")In [6]: blank_fn("foobar", bar="foo")In [7]: