holoviz / param

Param: Make your Python code clearer and more reliable by declaring Parameters
https://param.holoviz.org
BSD 3-Clause "New" or "Revised" License
410 stars 69 forks source link

Should methods on Parameterizeds be treated as references by default #936

Open MarcSkovMadsen opened 2 months ago

MarcSkovMadsen commented 2 months ago

panel==1.4.1

When using a parameterized class methods that are not explicitly annotated with .depends my understanding is that they implicitly depend on all class parameters. Thus I should be able to use them as references just as methods marked with .depends.

I cannot when using Tabulator.

import panel as pn
import param
import pandas as pd

pn.extension()

class CustomComponent(pn.viewable.Viewer):
    value = param.Integer(default=2, bounds=(1,10))

    # @param.depends("value")
    def data(self):
        return pd.DataFrame({"x": [self.value]*self.value})

    def __panel__(self):
        return pn.Column(
            self.param.value,
            pn.widgets.Tabulator(self.data, pagination="remote", page_size=10)
        )

pn.extension("tabulator")
CustomComponent().servable()

image

It works without the using Tabulator or if I .depends on the value.

philippjfr commented 2 months ago

Reference resolution happens at the param level so I've transferred this for now and marked it as a discussion point. @MarcSkovMadsen is correct that in other scenarios we do treated un-annotated methods as if they depended on all parameters so making them valid references would be consistent.

maximlt commented 2 months ago

in other scenarios we do treated un-annotated methods as if they depended on all parameters

Does anyone remember the rationale for this behavior? (I'd rather have to type something explicit like param.depends('*'))

philippjfr commented 2 months ago

Does anyone remember the rationale for this behavior?

Yes, @jbednar strongly argued that it would be easy to forget to declare the dependencies so this was the safe default behavior. I've wavered on this in the past but think generally it was the right default behavior.