Skip to content

Instantly share code, notes, and snippets.

@Rustam-Z
Created August 9, 2021 10:33
Show Gist options
  • Save Rustam-Z/23264c1b9ee6e2173bf7f2650926f2fd to your computer and use it in GitHub Desktop.
Save Rustam-Z/23264c1b9ee6e2173bf7f2650926f2fd to your computer and use it in GitHub Desktop.
def print_return_type(func):
# Define wrapper(), the decorated function
def wrapper(*args, **kwargs):
# Call the function being decorated
result = func(*args, **kwargs)
print('{}() returned type {}'.format(
func.__name__, type(result)
))
return result
# Return the decorated function
return wrapper
@print_return_type
def foo(value):
return value
print(foo(42))
print(foo([1, 2, 3]))
print(foo({'a': 42}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment