Get closure variables used by a function in Python

def get_function_closures(fn):
    return (*(
            closure.cell_contents
            for closure
            in fn.__closure__
        ),)

Related: