Skip to content
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 11 commits into from Jul 31, 2017


Copy link

@pbugnion 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.
Copy link

@jasongrout 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
jasongrout added a commit to jasongrout/ipywidgets that referenced this issue Jul 31, 2017
@jasongrout jasongrout added this to the 7.0 milestone Aug 1, 2017
@jasongrout jasongrout added this to the 7.0 milestone Aug 1, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants