@@ -24,7 +24,33 @@ a class or instance provides a particular interface, for example, is it
2424hashable or a mapping.
2525
2626
27- This module provides the following classes:
27+ This module provides the metaclass :class: `ABCMeta ` for defining ABCs and
28+ a helper class :class: `ABC ` to alternatively define ABCs through inheritance:
29+
30+ .. class :: ABC
31+
32+ A helper class that has :class: `ABCMeta ` as its metaclass. With this class,
33+ an abstract base class can be created by simply deriving from :class: `ABC `
34+ avoiding sometimes confusing metaclass usage, for example::
35+
36+ from abc import ABC
37+
38+ class MyABC(ABC):
39+ pass
40+
41+ Note that the type of :class: `ABC ` is still :class: `ABCMeta `, therefore
42+ inheriting from :class: `ABC ` requires the usual precautions regarding
43+ metaclass usage, as multiple inheritance may lead to metaclass conflicts.
44+ One may also define an abstract base class by passing the metaclass
45+ keyword and using :class: `ABCMeta ` directly, for example::
46+
47+ from abc import ABCMeta
48+
49+ class MyABC(metaclass=ABCMeta):
50+ pass
51+
52+ .. versionadded :: 3.4
53+
2854
2955.. class :: ABCMeta
3056
@@ -46,15 +72,15 @@ This module provides the following classes:
4672 Register *subclass * as a "virtual subclass" of this ABC. For
4773 example::
4874
49- from abc import ABCMeta
75+ from abc import ABC
5076
51- class MyABC(metaclass=ABCMeta ):
52- pass
77+ class MyABC(ABC ):
78+ pass
5379
54- MyABC.register(tuple)
80+ MyABC.register(tuple)
5581
56- assert issubclass(tuple, MyABC)
57- assert isinstance((), MyABC)
82+ assert issubclass(tuple, MyABC)
83+ assert isinstance((), MyABC)
5884
5985 .. versionchanged :: 3.3
6086 Returns the registered subclass, to allow usage as a class decorator.
@@ -95,7 +121,7 @@ This module provides the following classes:
95121 def get_iterator(self):
96122 return iter(self)
97123
98- class MyIterable(metaclass=ABCMeta ):
124+ class MyIterable(ABC ):
99125
100126 @abstractmethod
101127 def __iter__(self):
@@ -132,17 +158,6 @@ This module provides the following classes:
132158 available as a method of ``Foo ``, so it is provided separately.
133159
134160
135- .. class :: ABC
136-
137- A helper class that has :class: `ABCMeta ` as its metaclass. With this class,
138- an abstract base class can be created by simply deriving from :class: `ABC `,
139- avoiding sometimes confusing metaclass usage.
140-
141- Note that the type of :class: `ABC ` is still :class: `ABCMeta `, therefore
142- inheriting from :class: `ABC ` requires the usual precautions regarding metaclass
143- usage, as multiple inheritance may lead to metaclass conflicts.
144-
145- .. versionadded :: 3.4
146161
147162
148163The :mod: `abc ` module also provides the following decorators:
@@ -168,7 +183,7 @@ The :mod:`abc` module also provides the following decorators:
168183 descriptors, it should be applied as the innermost decorator, as shown in
169184 the following usage examples::
170185
171- class C(metaclass=ABCMeta ):
186+ class C(ABC ):
172187 @abstractmethod
173188 def my_abstract_method(self, ...):
174189 ...
@@ -230,7 +245,7 @@ The :mod:`abc` module also provides the following decorators:
230245 is now correctly identified as abstract when applied to an abstract
231246 method::
232247
233- class C(metaclass=ABCMeta ):
248+ class C(ABC ):
234249 @classmethod
235250 @abstractmethod
236251 def my_abstract_classmethod(cls, ...):
@@ -251,7 +266,7 @@ The :mod:`abc` module also provides the following decorators:
251266 is now correctly identified as abstract when applied to an abstract
252267 method::
253268
254- class C(metaclass=ABCMeta ):
269+ class C(ABC ):
255270 @staticmethod
256271 @abstractmethod
257272 def my_abstract_staticmethod(...):
@@ -278,7 +293,7 @@ The :mod:`abc` module also provides the following decorators:
278293 is now correctly identified as abstract when applied to an abstract
279294 method::
280295
281- class C(metaclass=ABCMeta ):
296+ class C(ABC ):
282297 @property
283298 @abstractmethod
284299 def my_abstract_property(self):
@@ -288,7 +303,7 @@ The :mod:`abc` module also provides the following decorators:
288303 read-write abstract property by appropriately marking one or more of the
289304 underlying methods as abstract::
290305
291- class C(metaclass=ABCMeta ):
306+ class C(ABC ):
292307 @property
293308 def x(self):
294309 ...
0 commit comments