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 debug_transformer(fun): | |
def wrapper(): | |
print(f'Function `{fun.__name__}` called') | |
fun() | |
print(f'Function `{fun.__name__}` finished') | |
return wrapper | |
@debug_transformer |
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
# Before | |
walkout = debug_transformer(walkout) | |
# After | |
@debug_transformer | |
def walkout(): | |
print('Bye Felicia') |
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 debug_transformer(fun): | |
def wrapper(): | |
print(f'Function `{fun.__name__}` called') | |
fun() | |
print(f'Function `{fun.__name__}` finished') | |
return wrapper | |
@debug_transformer |
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 wrapper(): | |
print(f'Function `{fun.__name__}` called') | |
fun() # Original reference to walkout() | |
print(f'Function `{fun.__name__}` finished') |
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
walkout = debug_transformer(walkout) |
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
Function `walkout` called | |
Bye Felicia | |
Function `walkout` finished |
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 walkout(): | |
print('Bye Felicia') | |
def debug_transformer(fun): | |
def wrapper(): | |
print(f'Function `{fun.__name__}` called') | |
fun() | |
print(f'Function `{fun.__name__}` finished') | |
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
Hello, Bob! | |
Goodbye, Bob! |
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 say_hello(name): | |
print(f'Hello, {name}!') | |
def say_goodbye(name): | |
print(f'Goodbye, {name}!') | |
def get_greeting(greeting): | |
if greeting == 'hello': |
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
>>> say_to_bob(say_hello()) | |
TypeError: say_hello() missing 1 required positional argument: 'name' |