How to add parameters per class instance instead for all instances of a class?

Hello,

I’m wondering how it was possible to dynamically add parameters to the instance of a class? The “add_parameter” function seems to affect all class instances.

class TestClass(param.Parameterized):
    param0 = param.String(default="always here")

    def __init__(self, initial_param: str, **params):
        super().__init__(**params)
        self.param0 = initial_param

instance1 = TestClass(initial_param="always here 1")
instance2 = TestClass(initial_param="always here 2")
instance1
=> TestClass(name='TestClass00002', param0='always here 1')

instance1.param.add_parameter("param1", param.String(default="only here with 1"))
instance1
=> TestClass(name='TestClass00002', param0='always here 1', param1='only here with 1')

instance2.param.add_parameter("param2", param.String(default="only here with 2"))
instance2
=> TestClass(name='TestClass00003', param0='always here 2', param1='only here with 1', param2='only here with 2')

instance1
=>  TestClass(name='TestClass00002', param0='always here 1', param1='only here with 1', param2='only here with 2')

Hi,

For params known at instantiation I use the per_instance parameter but the add_parameter method does not allow that. Maybe it should.