]> granicus.if.org Git - python/commitdiff
Add documentation and warnings for the isCallable(), isMappingType(),
authorFred Drake <fdrake@acm.org>
Mon, 2 Oct 2000 03:36:18 +0000 (03:36 +0000)
committerFred Drake <fdrake@acm.org>
Mon, 2 Oct 2000 03:36:18 +0000 (03:36 +0000)
isNumberType(), and isSequenceType() functions.

This closes SourceForge bug #115789.

Doc/lib/liboperator.tex

index 9cf25a07ab8eef407707d90cb6471d525b936367..69ae23b048f78fa7aa23d1c2fda965a7e1ca3711 100644 (file)
@@ -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.