DictModel generates invalid python attribute names
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
neutron |
Fix Released
|
Low
|
Yves-Gwenael Bourhis |
Bug Description
neutron.
On an instance of neutron.
i.e.:
ipdb> dir(self.network) # 'self' is an instance of neutron.
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_ns_name', 'admin_state_up', 'id', 'name', 'namespace', 'ports', 'provider:
As you can see, 'network.
Is there a reason why DictModel is not simply a subclass of dict with a __getattr__ method which would call __getitem__ on the dict? This would give attribute access to values "when the keys respect variable names", and dict keys which do not have the proper naming rules would still be accessible via the classical dict key access mechanism.
example:
>>> class DictModelExampl
>>> def __getattr__(self, name):
>>> return self[name]
>>> def __setattr__(self, name, value):
>>> self[name] = value
>>>
>>> d = {'a': 'foo'}
>>> d = DictModelExample(d)
>>> d.a
... 'foo'
>>> d.b = 'bar'
>>> d
... {'a': 'foo', 'b': 'bar'}
off course, we would keep the part in the __init__ method which converts dict values to DictModel.
description: | updated |
description: | updated |
description: | updated |
description: | updated |
Changed in neutron: | |
milestone: | none → juno-1 |
status: | Fix Committed → Fix Released |
Changed in neutron: | |
milestone: | juno-1 → 2014.2 |
DictModel really needs to go away, but it will probably be J before we should tackle that refactor to using real objects.