@@ -127,32 +127,71 @@ This module provides the following class:
127127 available as a method of ``Foo ``, so it is provided separately.
128128
129129
130- It also provides the following decorators:
130+ The :mod: ` abc ` module also provides the following decorators:
131131
132132.. decorator :: abstractmethod(function)
133133
134134 A decorator indicating abstract methods.
135135
136- Using this decorator requires that the class's metaclass is :class: `ABCMeta ` or
137- is derived from it.
138- A class that has a metaclass derived from :class: `ABCMeta `
139- cannot be instantiated unless all of its abstract methods and
140- properties are overridden.
141- The abstract methods can be called using any of the normal 'super' call
142- mechanisms.
136+ Using this decorator requires that the class's metaclass is :class: `ABCMeta `
137+ or is derived from it. A class that has a metaclass derived from
138+ :class: `ABCMeta ` cannot be instantiated unless all of its abstract methods
139+ and properties are overridden. The abstract methods can be called using any
140+ of the normal 'super' call mechanisms. :func: `abstractmethod ` may be used
141+ to declare abstract methods for properties and descriptors.
143142
144143 Dynamically adding abstract methods to a class, or attempting to modify the
145144 abstraction status of a method or class once it is created, are not
146145 supported. The :func: `abstractmethod ` only affects subclasses derived using
147146 regular inheritance; "virtual subclasses" registered with the ABC's
148147 :meth: `register ` method are not affected.
149148
150- Usage::
149+ When :func: `abstractmethod ` is applied in combination with other method
150+ descriptors, it should be applied as the innermost decorator, as shown in
151+ the following usage examples::
151152
152153 class C(metaclass=ABCMeta):
153154 @abstractmethod
154155 def my_abstract_method(self, ...):
155156 ...
157+ @classmethod
158+ @abstractmethod
159+ def my_abstract_classmethod(cls, ...):
160+ ...
161+ @staticmethod
162+ @abstractmethod
163+ def my_abstract_staticmethod(...):
164+ ...
165+
166+ @property
167+ @abstractmethod
168+ def my_abstract_property(self):
169+ ...
170+ @my_abstract_property.setter
171+ @abstractmethod
172+ def my_abstract_property(self, val):
173+ ...
174+
175+ @abstractmethod
176+ def _get_x(self):
177+ ...
178+ @abstractmethod
179+ def _set_x(self, val):
180+ ...
181+ x = property(_get_x, _set_x)
182+
183+ In order to correctly interoperate with the abstract base class machinery,
184+ the descriptor must identify itself as abstract using
185+ :attr: `__isabstractmethod__ `. In general, this attribute should be ``True ``
186+ if any of the methods used to compose the descriptor are abstract. For
187+ example, Python's built-in property does the equivalent of::
188+
189+ class Descriptor:
190+ ...
191+ @property
192+ def __isabstractmethod__(self):
193+ return any(getattr(f, '__isabstractmethod__', False) for
194+ f in (self._fget, self._fset, self._fdel))
156195
157196 .. note ::
158197
@@ -177,6 +216,8 @@ It also provides the following decorators:
177216 ...
178217
179218 .. versionadded :: 3.2
219+ .. deprecated :: 3.3
220+ Use :class: `classmethod ` with :func: `abstractmethod ` instead
180221
181222
182223.. decorator :: abstractstaticmethod(function)
@@ -192,18 +233,19 @@ It also provides the following decorators:
192233 ...
193234
194235 .. versionadded :: 3.2
236+ .. deprecated :: 3.3
237+ Use :class: `staticmethod ` with :func: `abstractmethod ` instead
195238
196239
197240.. decorator :: abstractproperty(fget=None, fset=None, fdel=None, doc=None)
198241
199242 A subclass of the built-in :func: `property `, indicating an abstract property.
200243
201- Using this function requires that the class's metaclass is :class: `ABCMeta ` or
202- is derived from it.
203- A class that has a metaclass derived from :class: `ABCMeta ` cannot be
204- instantiated unless all of its abstract methods and properties are overridden.
205- The abstract properties can be called using any of the normal
206- 'super' call mechanisms.
244+ Using this function requires that the class's metaclass is :class: `ABCMeta `
245+ or is derived from it. A class that has a metaclass derived from
246+ :class: `ABCMeta ` cannot be instantiated unless all of its abstract methods
247+ and properties are overridden. The abstract properties can be called using
248+ any of the normal 'super' call mechanisms.
207249
208250 Usage::
209251
@@ -220,6 +262,9 @@ It also provides the following decorators:
220262 def setx(self, value): ...
221263 x = abstractproperty(getx, setx)
222264
265+ .. deprecated :: 3.3
266+ Use :class: `property ` with :func: `abstractmethod ` instead
267+
223268
224269.. rubric :: Footnotes
225270
0 commit comments