diff Doc/lib/liboperator.tex @ 14965:1aa37008fd2c legacy-trunk

Add documentation and warnings for the isCallable(), isMappingType(), isNumberType(), and isSequenceType() functions. This closes SourceForge bug #115789.
author Fred Drake <fdrake@acm.org>
date Mon, 02 Oct 2000 03:36:18 +0000
parents 0228914e0c5f
children 103612516aa8
line wrap: on
line diff
--- a/Doc/lib/liboperator.tex	Mon Oct 02 02:25:51 2000 +0000
+++ b/Doc/lib/liboperator.tex	Mon Oct 02 03:36:18 2000 +0000
@@ -159,6 +159,56 @@
 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.