[pypy-svn] r32764 - in pypy/branch/even-more-config/pypy/config: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Sat Sep 30 13:18:33 CEST 2006
Author: cfbolz
Date: Sat Sep 30 13:18:30 2006
New Revision: 32764
Modified:
pypy/branch/even-more-config/pypy/config/config.py
pypy/branch/even-more-config/pypy/config/test/test_config.py
Log:
don't store the values in the __dict__ anymore
Modified: pypy/branch/even-more-config/pypy/config/config.py
==============================================================================
--- pypy/branch/even-more-config/pypy/config/config.py (original)
+++ pypy/branch/even-more-config/pypy/config/config.py Sat Sep 30 13:18:30 2006
@@ -8,16 +8,17 @@
self._cprefix_descr = descr
self._cprefix_value_owners = {}
self._cprefix_parent = parent
+ self._cprefix_values = {}
self._cprefix_build(overrides)
self._cprefix_read = {}
def _cprefix_build(self, overrides):
for child in self._cprefix_descr._children:
if isinstance(child, Option):
- self.__dict__[child._name] = child.default
+ self._cprefix_values[child._name] = child.default
self._cprefix_value_owners[child._name] = 'default'
elif isinstance(child, OptionDescription):
- self.__dict__[child._name] = Config(child, parent=self)
+ self._cprefix_values[child._name] = Config(child, parent=self)
self.override(overrides)
def override(self, overrides):
@@ -26,15 +27,21 @@
setattr(subconfig, name, value)
def __setattr__(self, name, value):
- if self._cprefix_frozen:
+ if self._cprefix_frozen and getattr(self, name) != value:
raise TypeError("trying to change a frozen option object")
if name.startswith('_cprefix_'):
self.__dict__[name] = value
return
self.setoption(name, value, 'user')
+ def __getattr__(self, name):
+ if name not in self._cprefix_values:
+ raise AttributeError("%s object has no attribute %s" %
+ (self.__class__, name))
+ return self._cprefix_values[name]
+
def setoption(self, name, value, who):
- if name not in self.__dict__:
+ if name not in self._cprefix_values:
raise ValueError('unknown option %s' % (name,))
child = getattr(self._cprefix_descr, name)
oldowner = self._cprefix_value_owners[child._name]
@@ -141,7 +148,7 @@
name = self._name
if not self.validate(value):
raise ValueError('invalid value %s for option %s' % (value, name))
- config.__dict__[name] = value
+ config._cprefix_values[name] = value
def getkey(self, value):
return value
Modified: pypy/branch/even-more-config/pypy/config/test/test_config.py
==============================================================================
--- pypy/branch/even-more-config/pypy/config/test/test_config.py (original)
+++ pypy/branch/even-more-config/pypy/config/test/test_config.py Sat Sep 30 13:18:30 2006
@@ -77,6 +77,8 @@
assert block.operations[0].opname == 'int_add'
assert config._freeze_()
+ # does not raise, since it does not change the attribute
+ config.gc.name = "ref"
py.test.raises(TypeError, 'config.gc.name = "framework"')
def test_compare_configs():
More information about the Pypy-commit
mailing list