diff options
author | Mark Summerfield <list@qtrac.plus.com> | 2007-09-05 08:43:04 (GMT) |
---|---|---|
committer | Mark Summerfield <list@qtrac.plus.com> | 2007-09-05 08:43:04 (GMT) |
commit | 08898b4b19a0cf0a5707efc3e64c0d2e3cf3d82f (patch) | |
tree | 2a74e2dc82273746fb964601f70ed23a849ba736 /Doc/library/collections.rst | |
parent | fd4a7de172c7eb8d79a4cd648f65eaa552cd175f (diff) | |
download | cpython-08898b4b19a0cf0a5707efc3e64c0d2e3cf3d82f.zip cpython-08898b4b19a0cf0a5707efc3e64c0d2e3cf3d82f.tar.gz cpython-08898b4b19a0cf0a5707efc3e64c0d2e3cf3d82f.tar.bz2 |
Proof read/editing of abc. Added table of collections.Hashable etc. to
collections with some brief notes.
Diffstat (limited to 'Doc/library/collections.rst')
-rw-r--r-- | Doc/library/collections.rst | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 50ddc0f..fe57f12 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -19,6 +19,55 @@ or file based ordered dictionaries with string keys. Future editions of the standard library may include balanced trees and ordered dictionaries. +In addition to containers, the collections module provides some ABCs +(abstract base classes) that can be used to test whether +a class provides a particular interface, for example, is it hashable or +a mapping. The ABCs provided include those in the following table: + +===================================== ======================================== +ABC Notes +===================================== ======================================== +:class:`collections.Container` Defines ``__contains__()`` +:class:`collections.Hashable` Defines ``__hash__()`` +:class:`collections.Iterable` Defines ``__iter__()`` +:class:`collections.Iterator` Derived from :class:`Iterable` and in + addition defines ``__next__()`` +:class:`collections.Mapping` Derived from :class:`Container`, + :class:`Iterable`, + and :class:`Sized`, and in addition + defines ``__getitem__()``, ``get()``, + ``__contains__()``, ``__len__()``, + ``__iter__()``, ``keys()``, + ``items()``, and ``values()`` +:class:`collections.MutableMapping` Derived from :class:`Mapping` +:class:`collections.MutableSequence` Derived from :class:`Sequence` +:class:`collections.MutableSet` Derived from :class:`Set` and in + addition defines ``add()``, + ``clear()``, ``discard()``, ``pop()``, + and ``toggle()`` +:class:`collections.Sequence` Derived from :class:`Container`, + :class:`Iterable`, and :class:`Sized`, + and in addition defines + ``__getitem__()`` +:class:`collections.Set` Derived from :class:`Container`, :class:`Iterable`, and :class:`Sized` +:class:`collections.Sized` Defines ``__len__()`` +===================================== ======================================== + +.. XXX Have not included them all and the notes are imcomplete +.. Deliberately did one row wide to get a neater output + +These ABCs allow us to ask classes or instances if they provide +particular functionality, for example:: + + from collections import Sized + + size = None + if isinstance(myvar, Sized): + size = len(myvar) + +(For more about ABCs, see the :mod:`abc` module and :pep:`3119`.) + + .. _deque-objects: |