Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 1 | :mod:`abc` --- Abstract Base Classes |
| 2 | ==================================== |
| 3 | |
| 4 | .. module:: abc |
| 5 | :synopsis: Abstract base classes according to PEP 3119. |
| 6 | .. moduleauthor:: Guido van Rossum |
| 7 | .. sectionauthor:: Georg Brandl |
| 8 | .. much of the content adapted from docstrings |
| 9 | |
Raymond Hettinger | ead4975 | 2011-01-24 16:28:06 +0000 | [diff] [blame] | 10 | **Source code:** :source:`Lib/abc.py` |
| 11 | |
| 12 | -------------- |
| 13 | |
Éric Araujo | 8ddf7c2 | 2011-06-15 17:49:20 +0200 | [diff] [blame] | 14 | This module provides the infrastructure for defining :term:`abstract base |
Andrew Svetlov | b67596d | 2012-12-13 19:09:33 +0200 | [diff] [blame] | 15 | classes <abstract base class>` (ABCs) in Python, as outlined in :pep:`3119`; |
| 16 | see the PEP for why this was added to Python. (See also :pep:`3141` and the |
| 17 | :mod:`numbers` module regarding a type hierarchy for numbers based on ABCs.) |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 18 | |
Mark Summerfield | 08898b4 | 2007-09-05 08:43:04 +0000 | [diff] [blame] | 19 | The :mod:`collections` module has some concrete classes that derive from |
| 20 | ABCs; these can, of course, be further derived. In addition the |
Éric Araujo | 3622680 | 2011-06-03 20:49:39 +0200 | [diff] [blame] | 21 | :mod:`collections.abc` submodule has some ABCs that can be used to test whether |
Mark Summerfield | 08898b4 | 2007-09-05 08:43:04 +0000 | [diff] [blame] | 22 | a class or instance provides a particular interface, for example, is it |
| 23 | hashable or a mapping. |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 24 | |
| 25 | |
Andrew Svetlov | b67596d | 2012-12-13 19:09:33 +0200 | [diff] [blame] | 26 | This module provides the following classes: |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 27 | |
| 28 | .. class:: ABCMeta |
| 29 | |
| 30 | Metaclass for defining Abstract Base Classes (ABCs). |
| 31 | |
| 32 | Use this metaclass to create an ABC. An ABC can be subclassed directly, and |
| 33 | then acts as a mix-in class. You can also register unrelated concrete |
| 34 | classes (even built-in classes) and unrelated ABCs as "virtual subclasses" -- |
| 35 | these and their descendants will be considered subclasses of the registering |
| 36 | ABC by the built-in :func:`issubclass` function, but the registering ABC |
| 37 | won't show up in their MRO (Method Resolution Order) nor will method |
| 38 | implementations defined by the registering ABC be callable (not even via |
Mark Summerfield | 08898b4 | 2007-09-05 08:43:04 +0000 | [diff] [blame] | 39 | :func:`super`). [#]_ |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 40 | |
| 41 | Classes created with a metaclass of :class:`ABCMeta` have the following method: |
| 42 | |
| 43 | .. method:: register(subclass) |
| 44 | |
Mark Summerfield | 08898b4 | 2007-09-05 08:43:04 +0000 | [diff] [blame] | 45 | Register *subclass* as a "virtual subclass" of this ABC. For |
| 46 | example:: |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 47 | |
Georg Brandl | a1c6a1c | 2009-01-03 21:26:05 +0000 | [diff] [blame] | 48 | from abc import ABCMeta |
Mark Summerfield | 08898b4 | 2007-09-05 08:43:04 +0000 | [diff] [blame] | 49 | |
Georg Brandl | a1c6a1c | 2009-01-03 21:26:05 +0000 | [diff] [blame] | 50 | class MyABC(metaclass=ABCMeta): |
| 51 | pass |
Mark Summerfield | 08898b4 | 2007-09-05 08:43:04 +0000 | [diff] [blame] | 52 | |
Georg Brandl | a1c6a1c | 2009-01-03 21:26:05 +0000 | [diff] [blame] | 53 | MyABC.register(tuple) |
Mark Summerfield | 08898b4 | 2007-09-05 08:43:04 +0000 | [diff] [blame] | 54 | |
Georg Brandl | a1c6a1c | 2009-01-03 21:26:05 +0000 | [diff] [blame] | 55 | assert issubclass(tuple, MyABC) |
| 56 | assert isinstance((), MyABC) |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 57 | |
Éric Araujo | 6c3787c | 2011-02-24 18:03:10 +0000 | [diff] [blame] | 58 | .. versionchanged:: 3.3 |
| 59 | Returns the registered subclass, to allow usage as a class decorator. |
| 60 | |
Łukasz Langa | eadd8cf | 2013-05-25 18:41:50 +0200 | [diff] [blame] | 61 | .. versionchanged:: 3.4 |
| 62 | To detect calls to :meth:`register`, you can use the |
| 63 | :func:`get_cache_token` function. |
| 64 | |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 65 | You can also override this method in an abstract base class: |
| 66 | |
| 67 | .. method:: __subclasshook__(subclass) |
| 68 | |
| 69 | (Must be defined as a class method.) |
| 70 | |
| 71 | Check whether *subclass* is considered a subclass of this ABC. This means |
| 72 | that you can customize the behavior of ``issubclass`` further without the |
| 73 | need to call :meth:`register` on every class you want to consider a |
Georg Brandl | 2d14098 | 2007-09-04 15:45:25 +0000 | [diff] [blame] | 74 | subclass of the ABC. (This class method is called from the |
| 75 | :meth:`__subclasscheck__` method of the ABC.) |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 76 | |
| 77 | This method should return ``True``, ``False`` or ``NotImplemented``. If |
| 78 | it returns ``True``, the *subclass* is considered a subclass of this ABC. |
| 79 | If it returns ``False``, the *subclass* is not considered a subclass of |
| 80 | this ABC, even if it would normally be one. If it returns |
| 81 | ``NotImplemented``, the subclass check is continued with the usual |
| 82 | mechanism. |
| 83 | |
Georg Brandl | 2d14098 | 2007-09-04 15:45:25 +0000 | [diff] [blame] | 84 | .. XXX explain the "usual mechanism" |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 85 | |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 86 | |
Georg Brandl | 2d14098 | 2007-09-04 15:45:25 +0000 | [diff] [blame] | 87 | For a demonstration of these concepts, look at this example ABC definition:: |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 88 | |
Georg Brandl | 2d14098 | 2007-09-04 15:45:25 +0000 | [diff] [blame] | 89 | class Foo: |
| 90 | def __getitem__(self, index): |
| 91 | ... |
| 92 | def __len__(self): |
| 93 | ... |
| 94 | def get_iterator(self): |
| 95 | return iter(self) |
| 96 | |
| 97 | class MyIterable(metaclass=ABCMeta): |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 98 | |
| 99 | @abstractmethod |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 100 | def __iter__(self): |
Georg Brandl | 2d14098 | 2007-09-04 15:45:25 +0000 | [diff] [blame] | 101 | while False: |
| 102 | yield None |
| 103 | |
| 104 | def get_iterator(self): |
| 105 | return self.__iter__() |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 106 | |
| 107 | @classmethod |
| 108 | def __subclasshook__(cls, C): |
Georg Brandl | 2d14098 | 2007-09-04 15:45:25 +0000 | [diff] [blame] | 109 | if cls is MyIterable: |
| 110 | if any("__iter__" in B.__dict__ for B in C.__mro__): |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 111 | return True |
| 112 | return NotImplemented |
| 113 | |
Georg Brandl | 2d14098 | 2007-09-04 15:45:25 +0000 | [diff] [blame] | 114 | MyIterable.register(Foo) |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 115 | |
Georg Brandl | 2d14098 | 2007-09-04 15:45:25 +0000 | [diff] [blame] | 116 | The ABC ``MyIterable`` defines the standard iterable method, |
Serhiy Storchaka | bfdcd43 | 2013-10-13 23:09:14 +0300 | [diff] [blame] | 117 | :meth:`~iterator.__iter__`, as an abstract method. The implementation given |
| 118 | here can still be called from subclasses. The :meth:`get_iterator` method |
| 119 | is also part of the ``MyIterable`` abstract base class, but it does not have |
| 120 | to be overridden in non-abstract derived classes. |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 121 | |
| 122 | The :meth:`__subclasshook__` class method defined here says that any class |
Serhiy Storchaka | bfdcd43 | 2013-10-13 23:09:14 +0300 | [diff] [blame] | 123 | that has an :meth:`~iterator.__iter__` method in its |
| 124 | :attr:`~object.__dict__` (or in that of one of its base classes, accessed |
| 125 | via the :attr:`~class.__mro__` list) is considered a ``MyIterable`` too. |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 126 | |
Georg Brandl | 2d14098 | 2007-09-04 15:45:25 +0000 | [diff] [blame] | 127 | Finally, the last line makes ``Foo`` a virtual subclass of ``MyIterable``, |
Serhiy Storchaka | bfdcd43 | 2013-10-13 23:09:14 +0300 | [diff] [blame] | 128 | even though it does not define an :meth:`~iterator.__iter__` method (it uses |
| 129 | the old-style iterable protocol, defined in terms of :meth:`__len__` and |
Georg Brandl | 2d14098 | 2007-09-04 15:45:25 +0000 | [diff] [blame] | 130 | :meth:`__getitem__`). Note that this will not make ``get_iterator`` |
| 131 | available as a method of ``Foo``, so it is provided separately. |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 132 | |
| 133 | |
Andrew Svetlov | b67596d | 2012-12-13 19:09:33 +0200 | [diff] [blame] | 134 | .. class:: ABC |
| 135 | |
Georg Brandl | 09bc642 | 2012-12-16 13:32:33 +0100 | [diff] [blame] | 136 | A helper class that has :class:`ABCMeta` as its metaclass. With this class, |
| 137 | an abstract base class can be created by simply deriving from :class:`ABC`, |
Andrew Svetlov | b67596d | 2012-12-13 19:09:33 +0200 | [diff] [blame] | 138 | avoiding sometimes confusing metaclass usage. |
| 139 | |
Georg Brandl | 09bc642 | 2012-12-16 13:32:33 +0100 | [diff] [blame] | 140 | Note that the type of :class:`ABC` is still :class:`ABCMeta`, therefore |
| 141 | inheriting from :class:`ABC` requires the usual precautions regarding metaclass |
| 142 | usage, as multiple inheritance may lead to metaclass conflicts. |
| 143 | |
| 144 | .. versionadded:: 3.4 |
| 145 | |
Andrew Svetlov | b67596d | 2012-12-13 19:09:33 +0200 | [diff] [blame] | 146 | |
Benjamin Peterson | bfebb7b | 2011-12-15 15:34:02 -0500 | [diff] [blame] | 147 | The :mod:`abc` module also provides the following decorators: |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 148 | |
Éric Araujo | 9bc9ab5 | 2012-12-08 18:35:31 -0500 | [diff] [blame] | 149 | .. decorator:: abstractmethod |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 150 | |
| 151 | A decorator indicating abstract methods. |
| 152 | |
Benjamin Peterson | bfebb7b | 2011-12-15 15:34:02 -0500 | [diff] [blame] | 153 | Using this decorator requires that the class's metaclass is :class:`ABCMeta` |
| 154 | or is derived from it. A class that has a metaclass derived from |
| 155 | :class:`ABCMeta` cannot be instantiated unless all of its abstract methods |
| 156 | and properties are overridden. The abstract methods can be called using any |
| 157 | of the normal 'super' call mechanisms. :func:`abstractmethod` may be used |
| 158 | to declare abstract methods for properties and descriptors. |
Georg Brandl | 2d14098 | 2007-09-04 15:45:25 +0000 | [diff] [blame] | 159 | |
| 160 | Dynamically adding abstract methods to a class, or attempting to modify the |
| 161 | abstraction status of a method or class once it is created, are not |
| 162 | supported. The :func:`abstractmethod` only affects subclasses derived using |
| 163 | regular inheritance; "virtual subclasses" registered with the ABC's |
| 164 | :meth:`register` method are not affected. |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 165 | |
Benjamin Peterson | bfebb7b | 2011-12-15 15:34:02 -0500 | [diff] [blame] | 166 | When :func:`abstractmethod` is applied in combination with other method |
| 167 | descriptors, it should be applied as the innermost decorator, as shown in |
| 168 | the following usage examples:: |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 169 | |
| 170 | class C(metaclass=ABCMeta): |
| 171 | @abstractmethod |
| 172 | def my_abstract_method(self, ...): |
| 173 | ... |
Benjamin Peterson | bfebb7b | 2011-12-15 15:34:02 -0500 | [diff] [blame] | 174 | @classmethod |
| 175 | @abstractmethod |
| 176 | def my_abstract_classmethod(cls, ...): |
| 177 | ... |
| 178 | @staticmethod |
| 179 | @abstractmethod |
| 180 | def my_abstract_staticmethod(...): |
| 181 | ... |
| 182 | |
| 183 | @property |
| 184 | @abstractmethod |
| 185 | def my_abstract_property(self): |
| 186 | ... |
| 187 | @my_abstract_property.setter |
| 188 | @abstractmethod |
| 189 | def my_abstract_property(self, val): |
| 190 | ... |
| 191 | |
| 192 | @abstractmethod |
| 193 | def _get_x(self): |
| 194 | ... |
| 195 | @abstractmethod |
| 196 | def _set_x(self, val): |
| 197 | ... |
| 198 | x = property(_get_x, _set_x) |
| 199 | |
| 200 | In order to correctly interoperate with the abstract base class machinery, |
| 201 | the descriptor must identify itself as abstract using |
| 202 | :attr:`__isabstractmethod__`. In general, this attribute should be ``True`` |
| 203 | if any of the methods used to compose the descriptor are abstract. For |
| 204 | example, Python's built-in property does the equivalent of:: |
| 205 | |
| 206 | class Descriptor: |
| 207 | ... |
| 208 | @property |
| 209 | def __isabstractmethod__(self): |
| 210 | return any(getattr(f, '__isabstractmethod__', False) for |
| 211 | f in (self._fget, self._fset, self._fdel)) |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 212 | |
Georg Brandl | 2d14098 | 2007-09-04 15:45:25 +0000 | [diff] [blame] | 213 | .. note:: |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 214 | |
Benjamin Peterson | ad3d5c2 | 2009-02-26 03:38:59 +0000 | [diff] [blame] | 215 | Unlike Java abstract methods, these abstract |
Mark Summerfield | 08898b4 | 2007-09-05 08:43:04 +0000 | [diff] [blame] | 216 | methods may have an implementation. This implementation can be |
| 217 | called via the :func:`super` mechanism from the class that |
| 218 | overrides it. This could be useful as an end-point for a |
| 219 | super-call in a framework that uses cooperative |
| 220 | multiple-inheritance. |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 221 | |
Georg Brandl | 2d14098 | 2007-09-04 15:45:25 +0000 | [diff] [blame] | 222 | |
Éric Araujo | 9bc9ab5 | 2012-12-08 18:35:31 -0500 | [diff] [blame] | 223 | .. decorator:: abstractclassmethod |
Benjamin Peterson | 45c257f | 2010-08-17 00:52:52 +0000 | [diff] [blame] | 224 | |
| 225 | A subclass of the built-in :func:`classmethod`, indicating an abstract |
| 226 | classmethod. Otherwise it is similar to :func:`abstractmethod`. |
| 227 | |
Nick Coghlan | cea27be | 2012-12-08 22:56:02 +1000 | [diff] [blame] | 228 | This special case is deprecated, as the :func:`classmethod` decorator |
| 229 | is now correctly identified as abstract when applied to an abstract |
| 230 | method:: |
Benjamin Peterson | 45c257f | 2010-08-17 00:52:52 +0000 | [diff] [blame] | 231 | |
| 232 | class C(metaclass=ABCMeta): |
Nick Coghlan | cea27be | 2012-12-08 22:56:02 +1000 | [diff] [blame] | 233 | @classmethod |
| 234 | @abstractmethod |
Benjamin Peterson | 45c257f | 2010-08-17 00:52:52 +0000 | [diff] [blame] | 235 | def my_abstract_classmethod(cls, ...): |
| 236 | ... |
| 237 | |
Benjamin Peterson | ad1e0c5 | 2010-08-17 03:37:20 +0000 | [diff] [blame] | 238 | .. versionadded:: 3.2 |
Benjamin Peterson | bfebb7b | 2011-12-15 15:34:02 -0500 | [diff] [blame] | 239 | .. deprecated:: 3.3 |
Nick Coghlan | cea27be | 2012-12-08 22:56:02 +1000 | [diff] [blame] | 240 | It is now possible to use :class:`classmethod` with |
| 241 | :func:`abstractmethod`, making this decorator redundant. |
Benjamin Peterson | ad1e0c5 | 2010-08-17 03:37:20 +0000 | [diff] [blame] | 242 | |
Benjamin Peterson | 45c257f | 2010-08-17 00:52:52 +0000 | [diff] [blame] | 243 | |
Éric Araujo | 9bc9ab5 | 2012-12-08 18:35:31 -0500 | [diff] [blame] | 244 | .. decorator:: abstractstaticmethod |
Benjamin Peterson | 45c257f | 2010-08-17 00:52:52 +0000 | [diff] [blame] | 245 | |
| 246 | A subclass of the built-in :func:`staticmethod`, indicating an abstract |
| 247 | staticmethod. Otherwise it is similar to :func:`abstractmethod`. |
| 248 | |
Nick Coghlan | cea27be | 2012-12-08 22:56:02 +1000 | [diff] [blame] | 249 | This special case is deprecated, as the :func:`staticmethod` decorator |
| 250 | is now correctly identified as abstract when applied to an abstract |
| 251 | method:: |
Benjamin Peterson | 45c257f | 2010-08-17 00:52:52 +0000 | [diff] [blame] | 252 | |
| 253 | class C(metaclass=ABCMeta): |
Nick Coghlan | cea27be | 2012-12-08 22:56:02 +1000 | [diff] [blame] | 254 | @staticmethod |
| 255 | @abstractmethod |
Benjamin Peterson | 45c257f | 2010-08-17 00:52:52 +0000 | [diff] [blame] | 256 | def my_abstract_staticmethod(...): |
| 257 | ... |
| 258 | |
Benjamin Peterson | ad1e0c5 | 2010-08-17 03:37:20 +0000 | [diff] [blame] | 259 | .. versionadded:: 3.2 |
Benjamin Peterson | bfebb7b | 2011-12-15 15:34:02 -0500 | [diff] [blame] | 260 | .. deprecated:: 3.3 |
Nick Coghlan | cea27be | 2012-12-08 22:56:02 +1000 | [diff] [blame] | 261 | It is now possible to use :class:`staticmethod` with |
| 262 | :func:`abstractmethod`, making this decorator redundant. |
Benjamin Peterson | ad1e0c5 | 2010-08-17 03:37:20 +0000 | [diff] [blame] | 263 | |
Benjamin Peterson | 45c257f | 2010-08-17 00:52:52 +0000 | [diff] [blame] | 264 | |
Éric Araujo | 8755278 | 2011-08-19 03:53:51 +0200 | [diff] [blame] | 265 | .. decorator:: abstractproperty(fget=None, fset=None, fdel=None, doc=None) |
Georg Brandl | 2d14098 | 2007-09-04 15:45:25 +0000 | [diff] [blame] | 266 | |
Nick Coghlan | cea27be | 2012-12-08 22:56:02 +1000 | [diff] [blame] | 267 | A subclass of the built-in :func:`property`, indicating an abstract |
| 268 | property. |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 269 | |
Benjamin Peterson | bfebb7b | 2011-12-15 15:34:02 -0500 | [diff] [blame] | 270 | Using this function requires that the class's metaclass is :class:`ABCMeta` |
| 271 | or is derived from it. A class that has a metaclass derived from |
| 272 | :class:`ABCMeta` cannot be instantiated unless all of its abstract methods |
| 273 | and properties are overridden. The abstract properties can be called using |
| 274 | any of the normal 'super' call mechanisms. |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 275 | |
Nick Coghlan | cea27be | 2012-12-08 22:56:02 +1000 | [diff] [blame] | 276 | This special case is deprecated, as the :func:`property` decorator |
| 277 | is now correctly identified as abstract when applied to an abstract |
| 278 | method:: |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 279 | |
| 280 | class C(metaclass=ABCMeta): |
Nick Coghlan | cea27be | 2012-12-08 22:56:02 +1000 | [diff] [blame] | 281 | @property |
| 282 | @abstractmethod |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 283 | def my_abstract_property(self): |
| 284 | ... |
| 285 | |
Nick Coghlan | cea27be | 2012-12-08 22:56:02 +1000 | [diff] [blame] | 286 | The above example defines a read-only property; you can also define a |
| 287 | read-write abstract property by appropriately marking one or more of the |
| 288 | underlying methods as abstract:: |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 289 | |
| 290 | class C(metaclass=ABCMeta): |
Nick Coghlan | cea27be | 2012-12-08 22:56:02 +1000 | [diff] [blame] | 291 | @property |
| 292 | def x(self): |
| 293 | ... |
| 294 | |
| 295 | @x.setter |
| 296 | @abstractmethod |
| 297 | def x(self, val): |
| 298 | ... |
| 299 | |
| 300 | If only some components are abstract, only those components need to be |
| 301 | updated to create a concrete property in a subclass:: |
| 302 | |
| 303 | class D(C): |
| 304 | @C.x.setter |
| 305 | def x(self, val): |
| 306 | ... |
| 307 | |
Georg Brandl | aeaa546 | 2007-09-04 08:11:03 +0000 | [diff] [blame] | 308 | |
Benjamin Peterson | bfebb7b | 2011-12-15 15:34:02 -0500 | [diff] [blame] | 309 | .. deprecated:: 3.3 |
Nick Coghlan | cea27be | 2012-12-08 22:56:02 +1000 | [diff] [blame] | 310 | It is now possible to use :class:`property`, :meth:`property.getter`, |
| 311 | :meth:`property.setter` and :meth:`property.deleter` with |
| 312 | :func:`abstractmethod`, making this decorator redundant. |
Benjamin Peterson | bfebb7b | 2011-12-15 15:34:02 -0500 | [diff] [blame] | 313 | |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 314 | |
Łukasz Langa | eadd8cf | 2013-05-25 18:41:50 +0200 | [diff] [blame] | 315 | The :mod:`abc` module also provides the following functions: |
| 316 | |
| 317 | .. function:: get_cache_token() |
| 318 | |
| 319 | Returns the current abstract base class cache token. |
| 320 | |
R David Murray | 3edcc78 | 2013-12-24 16:13:32 -0500 | [diff] [blame] | 321 | The token is an opaque object (that supports equality testing) identifying |
| 322 | the current version of the abstract base class cache for virtual subclasses. |
| 323 | The token changes with every call to :meth:`ABCMeta.register` on any ABC. |
Łukasz Langa | eadd8cf | 2013-05-25 18:41:50 +0200 | [diff] [blame] | 324 | |
| 325 | .. versionadded:: 3.4 |
| 326 | |
| 327 | |
Mark Summerfield | 08898b4 | 2007-09-05 08:43:04 +0000 | [diff] [blame] | 328 | .. rubric:: Footnotes |
| 329 | |
| 330 | .. [#] C++ programmers should note that Python's virtual base class |
| 331 | concept is not the same as C++'s. |