Skip to content

Add traitlet for validating number format #1550

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

Merged
merged 11 commits into from
Jul 31, 2017

Conversation

pbugnion
Copy link
Member

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
Copy link
Member

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

@jasongrout jasongrout merged commit a455d9d into jupyter-widgets:master Jul 31, 2017
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
@github-actions github-actions bot added the resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label Feb 12, 2021
@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.
Labels
resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants