Skip to content

Implement ConfigItem via getattr, setattr overrides

Teng Jian Khoo requested to merge khoo/easyjet:cosmic-horror into master

@dguest, to avoid mucking about with ConfigItem.__dict__, I went even more gnarly. See just the last commit.

It's mostly as an exercise because I could believe this is more screwed up than I am aware of...

There are 3 elements:

  1. We want __getattr__ to access self._data for all _data's attributes, but we have to avoid infinite recursion when retrieving _data.
  2. We want __setattr__ to permit setting _data once only, so _initialised is a bit of a fake attribute (also not visible from keys()).
  3. We need to override deepcopy so that it doesn't hit the _initialised block on setting _data.
Edited by Teng Jian Khoo

Merge request reports