Skip to content

Instantly share code, notes, and snippets.

@louisswarren
Last active June 6, 2016 00:01
Show Gist options
  • Save louisswarren/9a90dbac588dab7bc935d0b491d12104 to your computer and use it in GitHub Desktop.
Save louisswarren/9a90dbac588dab7bc935d0b491d12104 to your computer and use it in GitHub Desktop.
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)
'foo'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment