Changeset 391 for python/trunk/Doc/library/abc.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/library/abc.rst
r2 r391 10 10 .. versionadded:: 2.6 11 11 12 This module provides the infrastructure for defining an :term:`abstract base 13 class` (ABCs) in Python, as outlined in :pep:`3119`; see the PEP for why this 12 **Source code:** :source:`Lib/abc.py` 13 14 -------------- 15 16 This module provides the infrastructure for defining :term:`abstract base 17 classes <abstract base class>` (ABCs) in Python, as outlined in :pep:`3119`; see the PEP for why this 14 18 was added to Python. (See also :pep:`3141` and the :mod:`numbers` module 15 19 regarding a type hierarchy for numbers based on ABCs.) … … 107 111 108 112 The ABC ``MyIterable`` defines the standard iterable method, 109 :meth:` __iter__`, as an abstract method. The implementation given here can110 still be called from subclasses. The :meth:`get_iterator` method is also111 part of the ``MyIterable`` abstract base class, but it does not have to be112 overridden in non-abstract derived classes.113 :meth:`~iterator.__iter__`, as an abstract method. The implementation given 114 here can still be called from subclasses. The :meth:`get_iterator` method 115 is also part of the ``MyIterable`` abstract base class, but it does not have 116 to be overridden in non-abstract derived classes. 113 117 114 118 The :meth:`__subclasshook__` class method defined here says that any class 115 that has an :meth:` __iter__` method in its :attr:`__dict__` (or in that of116 one of its base classes, accessed via the :attr:`__mro__` list) is117 considered a ``MyIterable`` too.119 that has an :meth:`~iterator.__iter__` method in its 120 :attr:`~object.__dict__` (or in that of one of its base classes, accessed 121 via the :attr:`~class.__mro__` list) is considered a ``MyIterable`` too. 118 122 119 123 Finally, the last line makes ``Foo`` a virtual subclass of ``MyIterable``, 120 even though it does not define an :meth:` __iter__` method (it uses the121 old-style iterable protocol, defined in terms of :meth:`__len__` and124 even though it does not define an :meth:`~iterator.__iter__` method (it uses 125 the old-style iterable protocol, defined in terms of :meth:`__len__` and 122 126 :meth:`__getitem__`). Note that this will not make ``get_iterator`` 123 127 available as a method of ``Foo``, so it is provided separately.
Note:
See TracChangeset
for help on using the changeset viewer.