param icon indicating copy to clipboard operation
param copied to clipboard

ListSelector doesn't check the type

Open maximlt opened this issue 4 years ago • 3 comments

There seems to be two issues with ListSelector.

It raises a TypeError when the type is wrong (e.g. p.ls = 1). Which doesn't sound so bad but param actually raises a ValueError in those cases, e.g. for a Number parameter: ValueError: Parameter 'n' only takes numeric values, not type <class 'str'>.. For consistency, should it also raise a ValueError?

ListSelector doesn't check that the type is a list which means that this snippet doesn't fail:

import param

class A(param.Parameterized):
    ls = param.ListSelector('ab', ['a', 'b', 'c', 'd'])

a = A()
a.ls = 'cd'

Is this a bug?

maximlt avatar Sep 19 '21 21:09 maximlt

It also doesn't set the default value as the first item of objects if default is not provided:

import param

class A(param.Parameterized):
    ls = param.ListSelector(objects=['a', 'b', 'c', 'd'])

a = A()
a.ls  is None  # True

maximlt avatar Sep 20 '21 00:09 maximlt

Yes, definite bug.

It also doesn't set the default value as the first item of objects if default is not provided:

It definitely shouldn't do that in any case, default=None is perfectly valid (and forces allow_None).

philippjfr avatar Sep 20 '21 12:09 philippjfr

It definitely shouldn't do that in any case, default=None is perfectly valid (and forces allow_None).

Oh yes right I thought for some reason that it had the same behavior as Selector.

maximlt avatar Sep 20 '21 22:09 maximlt