'Capturing a function call as dict [duplicate]

I'm trying to write a python function decorator, and part of my implementation is that I need to capture the function call and look through the supplied values. I already have the function signature by using inspect.signature, but I'm unsure how to compose it with passed arguments.

Say I had the following

def decorator(func):
    def wrapper(*args, **kwargs):
        print(some_function_signature_getter(func, *args, **kwargs))
        return func(*args, **kwargs)
    return wrapper


@decorator
def foo(a, b, *_, **kwargs):
    return a+b

print(foo(1, 2))

How can I implement some_function_signature_getter such that my output is something like the following:

{'a': 1, 'b': 2, '_':[], 'kwargs':{}}
3


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source