Skip to content

Instantly share code, notes, and snippets.

@moskomule
Created August 1, 2017 07:54
Show Gist options
  • Save moskomule/0ec708c0f5560406c85e5e077defbe01 to your computer and use it in GitHub Desktop.
Save moskomule/0ec708c0f5560406c85e5e077defbe01 to your computer and use it in GitHub Desktop.
from functools import singledispatch
import numpy as np
@singledispatch
def test_function(arg):
print("default")
@test_function.register(int)
def _(arg):
print(f"arg is integer {arg}")
@test_function.register(str)
def _(arg):
print(f"arg is string {arg}")
@test_function.register(np.ndarray)
def _(arg):
print(f"arg is ndarray {arg}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment