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

allow_None not enforced when set to False and the default value is None #870

Open
maximlt opened this issue Oct 6, 2023 · 1 comment
Open
Labels
type-bug Bug report

Comments

@maximlt
Copy link
Member

maximlt commented Oct 6, 2023

Setting allow_None to False when the default Parameter value is None automatically sets it to True. I believe Param shouldn't be doing that, when allow_None is explicitly set to False this value should be enforced. The annoying bit being that for Parameters whose default default value is None (like Callable below) you'd have to provide a value that is not None. Unless this applies only after the Parameter has been instantiated, to allow it to be instantiated with None as the value for default with allow_None=False, but preventing it to be set to None afterwards, which I believe is what you can do now with ObjectSelector.

import param

class A(param.Parameterized):
    c = param.Callable(allow_None=False)

print(A.param.c.allow_None)
# True!
@maximlt maximlt added the type-bug Bug report label Oct 6, 2023
@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Nov 3, 2023

Just got hit by this too. Would expect the below to raise an exception when trying to instantiate the Viewer. Not before.

import param

class Viewer(param.Parameterized):
    data = param.DataFrame(allow_None=False)

viewer = Viewer()

As an alternative we need a required argument that makes it mandatory to specify the value on instantiation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug Bug report
Projects
None yet
Development

No branches or pull requests

2 participants