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

Let's have a function/attribute wrapper #3

Open
jrbl opened this issue Sep 17, 2014 · 1 comment
Open

Let's have a function/attribute wrapper #3

jrbl opened this issue Sep 17, 2014 · 1 comment

Comments

@jrbl
Copy link
Owner

jrbl commented Sep 17, 2014

Let's have a wrapper for function calls or attribute lookups that lets us trace into things. IT would look something like this:
take:

   if is_logged_in(session, user):

and say like:

    if wtf_is_in(is_logged_in(session, user):

or even better:

    @wtf_is_in
    if is_logged_in(session, user):

and get output like this:

****DEBUG is_logged_in(session, user):
    return False from /path/to/sourcefile:119:is_logged_in(session_object, user_object)
    return False from /path/to/otherfile:1668:check_valid(session, user_object)
    return False from /path/to/session_model.py:450:email_address_validated(user_object)

This is different from the current wtf behavior because rather than inserting a tracing line into a function call at the top of the stack to see what went on below, we can insert tracing at the base of the stack to see where things go up above en route to returning us values.

This seems like it's probably hard to write. Unless inspect already does some magic here, we're looking at real source code inspection. Get the return value, figure out if it's a bare value or a variable reference. If it's a variable reference, figure out where the variable is defined, then trace into that, rinse and repeat. If it's a bare value, return the name of this thing as likely being the culprit.

@jrbl
Copy link
Owner Author

jrbl commented Oct 5, 2014

The standard library trace almost does what we want, but it dumps its output in a weird format on stderr, which is wrong.

It looks like we can implement what we want via sys.settrace though. For inspiration, see also function_trace, pytracer, decotrace, and tracerbullet.

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