The code below uses the context manager to ensure that the code 'set something up' and 'shut things down' is always executed. What I can't understand what role the yield keyword plays here and how the bar argument is declared.
@contextmanager
def function(foo):
# set something up
def nestedfunction(bar):
# do something with bar
pass
try:
yield nestedfunction
finally:
# shut things down
The function will be called as follows
reporter = function(foo)