Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trace_function decorator doesn't properly show the arguments #2

Open
dhylands opened this issue Aug 14, 2015 · 0 comments
Open

trace_function decorator doesn't properly show the arguments #2

dhylands opened this issue Aug 14, 2015 · 0 comments

Comments

@dhylands
Copy link

As presented, the trace_function

def trace_function(f):
    """Add tracing before and after a function"""
    def new_f(*args):
        """The decorated function."""
        print('Called {}({!r})'.format(f, *args))
        result = f(*args)
        print('Returning', result)
        return result
    return new_f

if __name__ == '__main__':
    def add(a, b):
        return a + b

    traced_add = trace_function(add)
    traced_add(2, 3)

only prints the first argument:

Called <function add at 0x7fe633b77950>(2)
Returning 5

By changing the first print line to look like:

        print('Called {}{!r}'.format(f, args))

then it will print all of the arguments:

Called <function add at 0x7f509a9c7950>(2, 3)
Returning 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant