Last active
June 6, 2016 00:01
-
-
Save louisswarren/9a90dbac588dab7bc935d0b491d12104 to your computer and use it in GitHub Desktop.
Functions with human-readable representations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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