summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-08-01 17:32:28 (GMT)
committerGuido van Rossum <guido@python.org>2007-08-01 17:32:28 (GMT)
commitb31339fa02e48282b88f82942539ecc12e74ea63 (patch)
tree76f052b89a5bf5bfa13f584f0173559ea44f41c2 /Lib
parente78178e2c05ec2bb628b70a8b5422bb4dae63343 (diff)
downloadcpython-b31339fa02e48282b88f82942539ecc12e74ea63.zip
cpython-b31339fa02e48282b88f82942539ecc12e74ea63.tar.gz
cpython-b31339fa02e48282b88f82942539ecc12e74ea63.tar.bz2
Add @abstractproperty.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/abc.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/abc.py b/Lib/abc.py
index ae5113a..ab6325e 100644
--- a/Lib/abc.py
+++ b/Lib/abc.py
@@ -24,6 +24,31 @@ def abstractmethod(funcobj):
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()).