Okay, so I know this sounds like it's about Mutable default arguments but I wonder if there is a different explanation since the attribute is dict
but no default is definied.
My code is similar to this:
params_dict = {'this_parameter': 15}
class SomeClass:
def __init__(self, params):
assert isinstance(params, dict)
self.config = params
def change_parameter(self, value):
self.config['this_parameter'] = value
When I initialize a = SomeClass(params_dict)
and then
b = SomeClass(params_dict)
b.change_parameter(100)
and then a.config
it prints {'this_parameter: 100}
.
To me this looks like the "bug" all beginners see sooner or later with the mutable default arguments, but since I didn't use defaults I was wondering how to fix this.
(I wouldn't have considered myself a beginner anymore until today, but now I do again, so please bear with me!