Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Functions with human-readable representations
def named_func(f):
return type('named_func', (), {
'__call__': lambda s, *a, **k: f(*a, **k),
'__repr__': lambda s: f.__name__,
'__name__': f.__name__,
'__doc__': f.__doc__,
>>> @named_func
... def foo(x):
... return x*x
>>> repr(foo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment