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

Add traitlet for validating number format #1550

Merged
merged 11 commits into from Jul 31, 2017

Conversation

Projects
None yet
2 participants
@pbugnion
Member

pbugnion commented Jul 29, 2017

Prior to this PR, the readout_format trait was validated as a unicode in the {Float,Int}{,Range}Slider widgets. If the format was not a valid d3 format, this lead to an exception being thrown client-side, but that exception wasn't visible to the user. This lead to issue #1544 .

This PR adds a trait that validates that the format string is correctly formatted. The code for this PR is very much inspired by the format specifier parsing code in d3-format.

>>> import ipywidgets as widgets
>>> widgets.FloatSlider(readout_format='..3f')
# [...] stack trace

TraitError: The 'readout_format' trait of a FloatSlider instance must be a valid number format, but a value of u'..3f' <type 'unicode'> was specified.
@jasongrout

This comment has been minimized.

Member

jasongrout commented Jul 31, 2017

Thanks. Looks good to me, and thanks for adding tests too!

@jasongrout jasongrout merged commit a455d9d into jupyter-widgets:master Jul 31, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

jasongrout added a commit to jasongrout/ipywidgets that referenced this pull request Jul 31, 2017

@jasongrout jasongrout modified the milestone: 7.0 Aug 1, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment