Closed zasdfgbnm closed 5 years ago
One use case is: https://github.com/zasdfgbnm/TorchSnooper
This is a tool that I just start writing to allow PySnooper work with PyTorch to help debugging PyTorch models.
Okay, this is nice. I wasn't sure I wanted to merge it because it adds complexity, but this could solve several problems, so let's do it.
I want you to add the following:
isinstance
will be used. (Lots of people want to customize how numpy.ndarray
is displayed.) To check whether each entry is a class, do isinstance(entry, type)
.get_shortish_repr
, create a function get_repr_function(item, custom_repr)
that does the logic of figuring out which repr
function to use. By the way, nice touch with the for..else
:)Tracer
class.@cool-RR I've made the changes according to your review. Hope it looks good this time. I am not sure if you are OK with adding numpy
as a test dependency, but this makes the test more like a real use case.
Oops,,,, seems that pypy does not support numpy? I will change the test and remove numpy...
Good job.
Given the problem with Pypy, I agree with not including numpy as a test dependency. Just test it on classes that you create that have a __repr__
and ensure that that __repr__
wasn't called, just the custom repr function that the user specified.
@cool-RR Sorry I didn't see your message. Does the way I am testing it using dict work?
Your test looks good, yes.
Good job! I'll make a release in 1-2 hours.
Notice that on your second commit, you used a different committer name, try to avoid that because it makes the AUTHORS script show your name twice.
This PR add an API to allow users to customize how values are printed.
To customize the print of value, the user need to pass an iterable of pairs (condition, action), where the condition will be checked in order to determine which action to take. The condition must be a callable thar return bools, and the action must return string which is the desired print of values.