implementing dynamic class attributes in Python 3.9 causing advanced patterns in instances.
I've been researching this but Can someone help me understand I've been banging my head against this for hours... I'm working with an scenario in Python 3.9 where I'm trying to dynamically add attributes to a class instance, but I'm working with unexpected behavior. I have the following setup: ```python class DynamicAttributes: def __init__(self): self.fixed_attr = 'I am fixed' def add_dynamic_attr(self, attr_name, attr_value): setattr(self, attr_name, attr_value) instance = DynamicAttributes() instance.add_dynamic_attr('dynamic_attr', 'I am dynamic') ``` When I access `instance.dynamic_attr`, it works as expected, but if I try to access `instance.__dict__`, I see that the output has the added attribute. However, when I attempt to iterate over attributes using `vars(instance)` or `instance.__dict__.items()`, I get an unexpected result: ```python for key, value in vars(instance).items(): print(f'{key}: {value}') ``` This prints: ``` fixed_attr: I am fixed ``` only showing the fixed attribute. I've also tried directly accessing `instance.dynamic_attr` which returns 'I am dynamic', but the iteration does not reflect this. Could this be related to how I'm using the class or a misunderstanding of the `__dict__` behavior? I also tried checking the `__slots__` mechanism, but I haven't defined any slots in my class. Is there something specific about Python 3.9 that might be affecting this behavior? Any insights would be greatly appreciated! For context: I'm using Python on Windows. Any help would be greatly appreciated! I'm working on a application that needs to handle this. Is this even possible? This is happening in both development and production on Ubuntu 22.04. Has anyone dealt with something similar?