summaryrefslogtreecommitdiffstats
path: root/Doc/library/abc.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library/abc.rst')
-rw-r--r--Doc/library/abc.rst54
1 files changed, 39 insertions, 15 deletions
diff --git a/Doc/library/abc.rst b/Doc/library/abc.rst
index ef8b08e..dcec19a 100644
--- a/Doc/library/abc.rst
+++ b/Doc/library/abc.rst
@@ -7,8 +7,6 @@
.. sectionauthor:: Georg Brandl
.. much of the content adapted from docstrings
-.. versionadded:: 2.6
-
**Source code:** :source:`Lib/abc.py`
--------------
@@ -49,8 +47,8 @@ This module provides the following class:
from abc import ABCMeta
- class MyABC:
- __metaclass__ = ABCMeta
+ class MyABC(metaclass=ABCMeta):
+ pass
MyABC.register(tuple)
@@ -81,7 +79,7 @@ This module provides the following class:
For a demonstration of these concepts, look at this example ABC definition::
- class Foo(object):
+ class Foo:
def __getitem__(self, index):
...
def __len__(self):
@@ -89,8 +87,7 @@ This module provides the following class:
def get_iterator(self):
return iter(self)
- class MyIterable:
- __metaclass__ = ABCMeta
+ class MyIterable(metaclass=ABCMeta):
@abstractmethod
def __iter__(self):
@@ -129,7 +126,7 @@ This module provides the following class:
It also provides the following decorators:
-.. function:: abstractmethod(function)
+.. decorator:: abstractmethod
A decorator indicating abstract methods.
@@ -149,8 +146,7 @@ It also provides the following decorators:
Usage::
- class C:
- __metaclass__ = ABCMeta
+ class C(metaclass=ABCMeta):
@abstractmethod
def my_abstract_method(self, ...):
...
@@ -165,7 +161,37 @@ It also provides the following decorators:
multiple-inheritance.
-.. function:: abstractproperty([fget[, fset[, fdel[, doc]]]])
+.. decorator:: abstractclassmethod
+
+ A subclass of the built-in :func:`classmethod`, indicating an abstract
+ classmethod. Otherwise it is similar to :func:`abstractmethod`.
+
+ Usage::
+
+ class C(metaclass=ABCMeta):
+ @abstractclassmethod
+ def my_abstract_classmethod(cls, ...):
+ ...
+
+ .. versionadded:: 3.2
+
+
+.. decorator:: abstractstaticmethod
+
+ A subclass of the built-in :func:`staticmethod`, indicating an abstract
+ staticmethod. Otherwise it is similar to :func:`abstractmethod`.
+
+ Usage::
+
+ class C(metaclass=ABCMeta):
+ @abstractstaticmethod
+ def my_abstract_staticmethod(...):
+ ...
+
+ .. versionadded:: 3.2
+
+
+.. function:: abstractproperty(fget=None, fset=None, fdel=None, doc=None)
A subclass of the built-in :func:`property`, indicating an abstract property.
@@ -178,8 +204,7 @@ It also provides the following decorators:
Usage::
- class C:
- __metaclass__ = ABCMeta
+ class C(metaclass=ABCMeta):
@abstractproperty
def my_abstract_property(self):
...
@@ -187,8 +212,7 @@ It also provides the following decorators:
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
+ class C(metaclass=ABCMeta):
def getx(self): ...
def setx(self, value): ...
x = abstractproperty(getx, setx)