Backport of functools.singledispatch from Python 3.4
