Created
August 9, 2021 10:33
-
-
Save Rustam-Z/23264c1b9ee6e2173bf7f2650926f2fd to your computer and use it in GitHub Desktop.
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 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