summaryrefslogtreecommitdiffstats
path: root/Doc/lib/liboperator.tex
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2000-10-02 03:36:18 (GMT)
committerFred Drake <fdrake@acm.org>2000-10-02 03:36:18 (GMT)
commit8d3312f4d18e0b620d3ba1780c9ea2fd283a1686 (patch)
tree1adf55e201e4e25f7c1fb01b1f77f8a228e5561e /Doc/lib/liboperator.tex
parent0295181fa6089d53268b87d6756363796cd7c27d (diff)
downloadcpython-8d3312f4d18e0b620d3ba1780c9ea2fd283a1686.zip
cpython-8d3312f4d18e0b620d3ba1780c9ea2fd283a1686.tar.gz
cpython-8d3312f4d18e0b620d3ba1780c9ea2fd283a1686.tar.bz2
Add documentation and warnings for the isCallable(), isMappingType(),
isNumberType(), and isSequenceType() functions. This closes SourceForge bug #115789.
Diffstat (limited to 'Doc/lib/liboperator.tex')
-rw-r--r--Doc/lib/liboperator.tex50
1 files changed, 50 insertions, 0 deletions
diff --git a/Doc/lib/liboperator.tex b/Doc/lib/liboperator.tex
index 9cf25a0..69ae23b 100644
--- a/Doc/lib/liboperator.tex
+++ b/Doc/lib/liboperator.tex
@@ -159,6 +159,56 @@ sequence \var{v}.
Delete the slice of \var{a} from index \var{b} to index \var{c}\code{-1}.
\end{funcdesc}
+The \module{operator} also defines a few predicates to test the type
+of objects. \strong{Note:} Be careful not to misinterpret the
+results of these functions; only \function{isCallable()} has any
+measure of reliability with instance objects. For example:
+
+\begin{verbatim}
+>>> class C:
+... pass
+...
+>>> import operator
+>>> o = C()
+>>> operator.isMappingType(o)
+1
+\end{verbatim}
+
+\begin{funcdesc}{isCallable}{o}
+\deprecated{2.0}{Use the \function{callable()} built-in function instead.}
+Returns true if the object \var{o} can be called like a function,
+otherwise it returns false. True is returned for functions, bound and
+unbound methods, class objects, and instance objects which support the
+\method{__call__()} method.
+\end{funcdesc}
+
+\begin{funcdesc}{isMappingType}{o}
+Returns true if the object \var{o} supports the mapping interface.
+This is true for dictionaries and all instance objects.
+\strong{Warning:} There is no reliable way to test if an instance
+supports the complete mapping protocol since the interface itself is
+ill-defined. This makes this test less useful than it otherwise might
+be.
+\end{funcdesc}
+
+\begin{funcdesc}{isNumberType}{o}
+Returns true if the object \var{o} represents a number. This is true
+for all numeric types implemented in C, and for all instance objects.
+\strong{Warning:} There is no reliable way to test if an instance
+supports the complete numeric interface since the interface itself is
+ill-defined. This makes this test less useful than it otherwise might
+be.
+\end{funcdesc}
+
+\begin{funcdesc}{isSequenceType}{o}
+Returns true if the object \var{o} supports the sequence protocol.
+This returns true for all objects which define sequence methods in C,
+and for all instance objects. \strong{Warning:} There is no reliable
+way to test if an instance supports the complete sequence interface
+since the interface itself is ill-defined. This makes this test less
+useful than it otherwise might be.
+\end{funcdesc}
+
Example: Build a dictionary that maps the ordinals from \code{0} to
\code{256} to their character equivalents.