[pypy-svn] r40736 - in pypy/dist/pypy/config: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Sun Mar 18 23:24:22 CET 2007


Author: cfbolz
Date: Sun Mar 18 23:24:19 2007
New Revision: 40736

Modified:
   pypy/dist/pypy/config/config.py
   pypy/dist/pypy/config/test/test_config.py
Log:
add a __delattr__ for debugging purposes


Modified: pypy/dist/pypy/config/config.py
==============================================================================
--- pypy/dist/pypy/config/config.py	(original)
+++ pypy/dist/pypy/config/config.py	Sun Mar 18 23:24:19 2007
@@ -74,6 +74,18 @@
                                  (self.__class__, name))
         return self._cfgimpl_values[name]
 
+    def __delattr__(self, name):
+        # XXX if you use delattr you are responsible for all bad things
+        # happening
+        if name.startswith('_cfgimpl_'):
+            del self.__dict__[name]
+            return
+        self._cfgimpl_value_owners[name] = 'default'
+        opt = getattr(self._cfgimpl_descr, name)
+        if isinstance(opt, OptionDescription):
+            raise AttributeError("can't option subgroup")
+        self._cfgimpl_values[name] = getattr(opt, 'default', None)
+
     def setoption(self, name, value, who):
         if name not in self._cfgimpl_values:
             raise AttributeError('unknown option %s' % (name,))

Modified: pypy/dist/pypy/config/test/test_config.py
==============================================================================
--- pypy/dist/pypy/config/test/test_config.py	(original)
+++ pypy/dist/pypy/config/test/test_config.py	Sun Mar 18 23:24:19 2007
@@ -471,3 +471,15 @@
     assert c.opt
     assert not c.toplevel
 
+def test_delattr():
+    descr = OptionDescription("opt", "", [
+    OptionDescription("s1", "", [
+        BoolOption("a", "", default=False)]),
+    IntOption("int", "", default=42)])
+    c = Config(descr)
+    c.int = 45
+    assert c.int == 45
+    del c.int
+    assert c.int == 42
+    c.int = 45
+    assert c.int == 45



More information about the Pypy-commit mailing list