[Python-checkins] r58929 - in python/trunk: Lib/test/test_descr.py Objects/descrobject.c

Jim Jewett jimjjewett at gmail.com
Mon Nov 12 01:25:51 CET 2007


On 11/11/07, Guido van Rossum <guido at python.org> wrote:
> On Nov 11, 2007 10:53 AM, Jim Jewett <jimjjewett at gmail.com> wrote:
> > On Nov 10, 2007, at 5:12 PM, guido.van.rossum wrote:

> > What does the D class show?  As nearly as I can tell, the only
> > difference is that it won't raise an Exception if the attribute wasn't
> > already there -- and this case isn't tested in either C or D.
>
> It shows how you can subclass a property.

> While admittedly there's no test that del C().foo raises an exception,
> there *is* a test that del D().foo doesn't raise an exception; note
> that it says "del d.foo" twice.

How about a side effect, such as a backup?

+    class D(C):
+        @C.foo.deleter
+        def foo(self):
+            self._oldfoo = self._foo
+            del self._foo

...

+    d = D()
+    d.foo = 24
+    assert d.foo == 24
+    del d.foo
+    assert d._oldfoo == 24


More information about the Python-checkins mailing list