param icon indicating copy to clipboard operation
param copied to clipboard

`objects` set on both class and instance with `on_init=True`

Open maximlt opened this issue 2 years ago • 3 comments

With on_init=True the objects of the selector are set both on the instance and the class in the callback.

image

Code:

class P(param.Parameterized):
    
    s = param.Selector()
    
    @param.depends('s', watch=True, on_init=True)
    def update(self):
        self.param.s.objects = list('abc')

p = P()

p.param.s.objects

P.param.s.objects

maximlt avatar Nov 19 '21 18:11 maximlt

The same error can be reproduced with setting up objects before super is called in a Parameterized constructor.

import param

class P(param.Parameterized):
    
    s = param.Selector()

    def __init__(self, **params):
        self.param.s.objects = list('abc')
        super().__init__(**params)
    
p = P()

assert P.param.s.objects == []  # Fails!

So there's a problem with how on_init is implemented. And I wonder if there would be a way to warn or error when a Parameter attribute is changed before super is called.

maximlt avatar Apr 13 '23 19:04 maximlt

The issue in my first post was fixed: image

Not in the second one though: image

maximlt avatar Oct 13 '23 08:10 maximlt

Honestly think the second behavior can't be supported properly, maybe we error there somehow.

philippjfr avatar Oct 13 '23 08:10 philippjfr