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

Merged
merged 4 commits into from Jul 16, 2018

Conversation

Projects
None yet
4 participants
@mwcraig
Contributor

mwcraig commented Jul 2, 2018

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.

@vidartf

vidartf approved these changes Jul 2, 2018

@vidartf

This comment has been minimized.

Member

vidartf commented Jul 2, 2018

One thing we did e.g. in nbdime and nbval was to say something like <base64 string, hash=ea628...>. You could do something similar (but maybe with a cut-off value of only around a 100 characters).

@SylvainCorlay

This comment has been minimized.

Member

SylvainCorlay commented Jul 5, 2018

This looks good to me.

mwcraig added some commits Jul 5, 2018

Override repr in Image to represent value in some way
This is based on @vidartf's suggestion, and includes a bit of copy+paste
from nbdime
@mwcraig

This comment has been minimized.

Contributor

mwcraig commented Jul 5, 2018

I modified this to always present the value (truncated along the lines that @vidartf suggested). A more general solution in widgets._repr_from_keys would probably be ideal, but for now this presents a value for Image but won't kill your browser.

# Truncate the value in the repr, since it will
# typically be very, very large.
def hash_string(s):

This comment has been minimized.

@jasongrout

jasongrout Jul 6, 2018

Member

Let's not define a new function every time we do a repr.

signature = []
sig_value = str(self.value)
if len(str(self.value)) > 100:
sig_value = '<base64, hash={}...>'.format(hash_string(sig_value)[:16])

This comment has been minimized.

@jasongrout

jasongrout Jul 6, 2018

Member

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.

@mwcraig

This comment has been minimized.

Contributor

mwcraig commented Jul 7, 2018

This just truncates long Image.value (added a couple tests too).

@jasongrout jasongrout added this to the 7.3 milestone Jul 16, 2018

@jasongrout

This comment has been minimized.

Member

jasongrout commented Jul 16, 2018

Looks great to me, and works well when I test it too. Thanks!

@jasongrout jasongrout merged commit 884e171 into jupyter-widgets:master Jul 16, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment