Conveniences for tracing entire classes or files
- Ngôn ngữ chính
- Python
- Star
- 1.5k
- Fork
- 42
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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?
1. 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?
1. 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.
2. 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.
2. 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.
3. 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).
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Đánh giá
Issue này chưa được đánh giá.