Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Side by Side Diff: Doc/library/abc.rst

Issue 18758: Fix internal references in the documentation
Patch Set: Created 6 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Doc/library/2to3.rst ('k') | Doc/library/asyncore.rst » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 :mod:`abc` --- Abstract Base Classes 1 :mod:`abc` --- Abstract Base Classes
2 ==================================== 2 ====================================
3 3
4 .. module:: abc 4 .. module:: abc
5 :synopsis: Abstract base classes according to PEP 3119. 5 :synopsis: Abstract base classes according to PEP 3119.
6 .. moduleauthor:: Guido van Rossum 6 .. moduleauthor:: Guido van Rossum
7 .. sectionauthor:: Georg Brandl 7 .. sectionauthor:: Georg Brandl
8 .. much of the content adapted from docstrings 8 .. much of the content adapted from docstrings
9 9
10 **Source code:** :source:`Lib/abc.py` 10 **Source code:** :source:`Lib/abc.py`
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 @classmethod 107 @classmethod
108 def __subclasshook__(cls, C): 108 def __subclasshook__(cls, C):
109 if cls is MyIterable: 109 if cls is MyIterable:
110 if any("__iter__" in B.__dict__ for B in C.__mro__): 110 if any("__iter__" in B.__dict__ for B in C.__mro__):
111 return True 111 return True
112 return NotImplemented 112 return NotImplemented
113 113
114 MyIterable.register(Foo) 114 MyIterable.register(Foo)
115 115
116 The ABC ``MyIterable`` defines the standard iterable method, 116 The ABC ``MyIterable`` defines the standard iterable method,
117 :meth:`__iter__`, as an abstract method. The implementation given here can 117 :meth:`~iterator.__iter__`, as an abstract method. The implementation given here can
118 still be called from subclasses. The :meth:`get_iterator` method is also 118 still be called from subclasses. The :meth:`get_iterator` method is also
119 part of the ``MyIterable`` abstract base class, but it does not have to be 119 part of the ``MyIterable`` abstract base class, but it does not have to be
120 overridden in non-abstract derived classes. 120 overridden in non-abstract derived classes.
121 121
122 The :meth:`__subclasshook__` class method defined here says that any class 122 The :meth:`__subclasshook__` class method defined here says that any class
123 that has an :meth:`__iter__` method in its :attr:`__dict__` (or in that of 123 that has an :meth:`~iterator.__iter__` method in its :attr:`~object.__dict__` (or in that of
124 one of its base classes, accessed via the :attr:`__mro__` list) is 124 one of its base classes, accessed via the :attr:`~class.__mro__` list) is
125 considered a ``MyIterable`` too. 125 considered a ``MyIterable`` too.
126 126
127 Finally, the last line makes ``Foo`` a virtual subclass of ``MyIterable``, 127 Finally, the last line makes ``Foo`` a virtual subclass of ``MyIterable``,
128 even though it does not define an :meth:`__iter__` method (it uses the 128 even though it does not define an :meth:`~iterator.__iter__` method (it uses the
129 old-style iterable protocol, defined in terms of :meth:`__len__` and 129 old-style iterable protocol, defined in terms of :meth:`__len__` and
130 :meth:`__getitem__`). Note that this will not make ``get_iterator`` 130 :meth:`__getitem__`). Note that this will not make ``get_iterator``
131 available as a method of ``Foo``, so it is provided separately. 131 available as a method of ``Foo``, so it is provided separately.
132 132
133 133
134 .. class:: ABC 134 .. class:: ABC
135 135
136 A helper class that has :class:`ABCMeta` as its metaclass. With this class, 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`, 137 an abstract base class can be created by simply deriving from :class:`ABC`,
138 avoiding sometimes confusing metaclass usage. 138 avoiding sometimes confusing metaclass usage.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 abstract base class cache for virtual subclasses. This number changes 322 abstract base class cache for virtual subclasses. This number changes
323 with every call to :meth:`ABCMeta.register` on any ABC. 323 with every call to :meth:`ABCMeta.register` on any ABC.
324 324
325 .. versionadded:: 3.4 325 .. versionadded:: 3.4
326 326
327 327
328 .. rubric:: Footnotes 328 .. rubric:: Footnotes
329 329
330 .. [#] C++ programmers should note that Python's virtual base class 330 .. [#] C++ programmers should note that Python's virtual base class
331 concept is not the same as C++'s. 331 concept is not the same as C++'s.
OLDNEW
« no previous file with comments | « Doc/library/2to3.rst ('k') | Doc/library/asyncore.rst » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+