-
Notifications
You must be signed in to change notification settings - Fork 949
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
Remove value from the Image repr #2111
Remove value from the Image repr #2111
Conversation
One thing we did e.g. in nbdime and nbval was to say something like |
This looks good to me. |
This is based on @vidartf's suggestion, and includes a bit of copy+paste from nbdime
I modified this to always present the value (truncated along the lines that @vidartf suggested). A more general solution in |
ipywidgets/widgets/widget_image.py
Outdated
# Truncate the value in the repr, since it will | ||
# typically be very, very large. | ||
|
||
def hash_string(s): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not define a new function every time we do a repr.
ipywidgets/widgets/widget_image.py
Outdated
signature = [] | ||
sig_value = str(self.value) | ||
if len(str(self.value)) > 100: | ||
sig_value = '<base64, hash={}...>'.format(hash_string(sig_value)[:16]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't know that it is base64, do we? It might be a very long URL.
I like your previous approach of just truncating. Or perhaps we should just enhance the existing repr keys mechanism to let us return a repr form for any key, rather than just whether to include the key or not.
This just truncates long |
Looks great to me, and works well when I test it too. Thanks! |
Right now
Image.__repr__
includes the value of the image...which bring my browser to a crashing halt for large images.This is likely not the ideal way to handle this; I'd be happy to change
widget.__repr__
to truncate all large values (over maybe 10k characters?) in the repr instead.