You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes you may want to trace large chunks of your project without having to stick a decorator on each one and without setting a high depth which would trace lots of functions you don't care about. Below are some possible APIs. Which would you like? Any alternative ideas?
Decorate a class to trace all of its methods. Simply put @snoop at the top of the class. The question is, what would this do?
Decorate all functions defined directly in the class by parsing the file and looking at the locations of function definitions. Involves some magic but is very doable.
Decorate all functions in the class __dict__, ignoring functions in base classes, but including functions that have been set as attributes rather than defined directly in the class.
I like option (i) because it can bypass decorators on the methods and access the original underlying functions. Someone decorating a class may not consider that function decorators can get in the way and be surprised when a function doesn't get snooped - they might even think it's not being called. On the other hand it would surprise experienced Python developers who would intuitively expect something like (ii). It would also require leaving the tracing function on at all times which would hurt performance and get in the way of other debuggers.
I could also provide both options and document them, but I'd prefer to keep the API lean and these concepts are not easy to explain concisely.
Call a function like snoop.this_file() which snoops all methods in the file. Again there are options similar to (i) and (ii) above, either tracing the functions defined statically in the file or dynamically looking at the global variables, descending into classes. The first option would again require keeping the tracer on at all times.
Call a function like snoop.files(lambda filename: some_condition), e.g. snoop.files(lambda filename: "my_package" in filename), to trace all files satisfying the condition. Hypothetically this could again have options like (i) and (ii), but it would almost certainly be (i).
The text was updated successfully, but these errors were encountered:
For tracing entire files, if we can have a -m module flag to run files directly without modifying the code, that would be great. Many tools provide this convenient flag to run the scripts.
Sometimes you may want to trace large chunks of your project without having to stick a decorator on each one and without setting a high depth which would trace lots of functions you don't care about. Below are some possible APIs. Which would you like? Any alternative ideas?
Decorate a class to trace all of its methods. Simply put
@snoop
at the top of the class. The question is, what would this do?__dict__
, ignoring functions in base classes, but including functions that have been set as attributes rather than defined directly in the class.I like option (i) because it can bypass decorators on the methods and access the original underlying functions. Someone decorating a class may not consider that function decorators can get in the way and be surprised when a function doesn't get snooped - they might even think it's not being called. On the other hand it would surprise experienced Python developers who would intuitively expect something like (ii). It would also require leaving the tracing function on at all times which would hurt performance and get in the way of other debuggers.
I could also provide both options and document them, but I'd prefer to keep the API lean and these concepts are not easy to explain concisely.
Call a function like
snoop.this_file()
which snoops all methods in the file. Again there are options similar to (i) and (ii) above, either tracing the functions defined statically in the file or dynamically looking at the global variables, descending into classes. The first option would again require keeping the tracer on at all times.Call a function like
snoop.files(lambda filename: some_condition)
, e.g.snoop.files(lambda filename: "my_package" in filename)
, to trace all files satisfying the condition. Hypothetically this could again have options like (i) and (ii), but it would almost certainly be (i).The text was updated successfully, but these errors were encountered: