Author: guido.van.rossum
Date: Wed Aug  1 19:32:28 2007
New Revision: 56648

Modified:
   python/branches/py3k-struni/Lib/abc.py
Log:
Add @abstractproperty.


Modified: python/branches/py3k-struni/Lib/abc.py
==============================================================================
--- python/branches/py3k-struni/Lib/abc.py      (original)
+++ python/branches/py3k-struni/Lib/abc.py      Wed Aug  1 19:32:28 2007
@@ -24,6 +24,31 @@
     return funcobj
 
 
+class abstractproperty(property):
+    """A decorator indicating abstract properties.
+
+    Requires that the metaclass is ABCMeta or derived from it.  A
+    class that has a metaclass derived from ABCMeta cannot be
+    instantiated unless all of its abstract properties are overridden.
+
+    Usage:
+
+        class C(metaclass=ABCMeta):
+            @abstractproperty
+            def my_abstract_property(self):
+                ...
+
+    This defines a read-only property; you can also define a read-write
+    abstract property using the 'long' form of property declaration:
+
+        class C(metaclass=ABCMeta):
+            def getx(self): ...
+            def setx(self, value): ...
+            x = abstractproperty(getx, setx)
+    """
+    __isabstractmethod__ = True
+
+
 class _Abstract(object):
 
     """Helper class inserted into the bases by ABCMeta (using _fix_bases()).
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to