Search code examples
pythonpython-3.xfunctional-programmingpython-decoratorsfunctools

Python generic functions dispatching


Is there are any way to dispatch a function which arguments may be:

  • single lambda-function (i.e. func(lambda x: x))
  • kwargs (i.e. func(a='some sting', b='some other string'))

As I see it, singledispatch decorator from functools only supports dispatching on the first argument, which in my case won't work. Am I missing something?


Solution

  • You are not missing anything. single dispatch won't solve your problem

    https://pypi.python.org/pypi/multipledispatch

    can help you with positional arguments but not keywords :(