Created
April 16, 2021 03:06
-
-
Save jaredyam/0b44e097ee2ef70d94f4efeafb404936 to your computer and use it in GitHub Desktop.
Python function __repr__
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
from functools import wraps | |
def show_func_repr(func): | |
@wraps(func) | |
def wrapper(*args, **kwargs): | |
print('{func}({args}{kwargs})'.format( | |
func=func.__name__, | |
args=', '.join([f'{arg!r}' for arg in args]), | |
kwargs=''.join([f', {k}={v!r}' for k, v in kwargs.items()]) | |
)) | |
return func(*args, **kwargs) | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment