mirror of https://github.com/python/cpython
Add documentation and warnings for the isCallable(), isMappingType(),
isNumberType(), and isSequenceType() functions. This closes SourceForge bug #115789.
This commit is contained in:
parent
0295181fa6
commit
8d3312f4d1
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue