ipywidgets-static icon indicating copy to clipboard operation
ipywidgets-static copied to clipboard

RangeWidget argument check

Open yoavram opened this issue 11 years ago • 3 comments

First of all - this is awesome. I ran RangeWidget(1,10,"turns") and it took me some time to understand that it's not working because the third argument is step. I suggest to check the type of the arguments in widgets.py line 42. If you agree than I can do it myself and create a PR

Cheers Yoav

yoavram avatar Dec 26 '13 14:12 yoavram

Is "turns" supposed to be the name of the widget?

If so, you would want to specify the keyword.

RangeWidget(1, 10, name="turns")

step, name, default, width, divclass and show_range are all optional keyword arguments. If used in order they don't require a keyword, but if you want to "pick and choose" from them you have to be explicit.

rgbkrk avatar Dec 26 '13 16:12 rgbkrk

It's worth pointing out that the RangeWidget was created with python's built-in range() in mind. range() takes step as it's last optional argument:

>>> range(1, 11)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> range(0, 30, 5)
[0, 5, 10, 15, 20, 25]
>>> range(0, 10, 3)

rgbkrk avatar Dec 26 '13 16:12 rgbkrk

I agree with both your comments. I only suggest that you check the type of the supplied input because if the type is wrong then the error can be swallowed up somewhere inside the mechanism and they whole thing just doesn't work without explicitly failing. For example, if I run range with turns as the third paramter I get an explicit error: TypeError: range() integer step argument expected, got str.

yoavram avatar Jan 06 '14 18:01 yoavram