Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8d3312f

Browse files
committed
Add documentation and warnings for the isCallable(), isMappingType(),
isNumberType(), and isSequenceType() functions. This closes SourceForge bug #115789.
1 parent 0295181 commit 8d3312f

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

Doc/lib/liboperator.tex

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,56 @@ \section{\module{operator} ---
159159
Delete the slice of \var{a} from index \var{b} to index \var{c}\code{-1}.
160160
\end{funcdesc}
161161

162+
The \module{operator} also defines a few predicates to test the type
163+
of objects. \strong{Note:} Be careful not to misinterpret the
164+
results of these functions; only \function{isCallable()} has any
165+
measure of reliability with instance objects. For example:
166+
167+
\begin{verbatim}
168+
>>> class C:
169+
... pass
170+
...
171+
>>> import operator
172+
>>> o = C()
173+
>>> operator.isMappingType(o)
174+
1
175+
\end{verbatim}
176+
177+
\begin{funcdesc}{isCallable}{o}
178+
\deprecated{2.0}{Use the \function{callable()} built-in function instead.}
179+
Returns true if the object \var{o} can be called like a function,
180+
otherwise it returns false. True is returned for functions, bound and
181+
unbound methods, class objects, and instance objects which support the
182+
\method{__call__()} method.
183+
\end{funcdesc}
184+
185+
\begin{funcdesc}{isMappingType}{o}
186+
Returns true if the object \var{o} supports the mapping interface.
187+
This is true for dictionaries and all instance objects.
188+
\strong{Warning:} There is no reliable way to test if an instance
189+
supports the complete mapping protocol since the interface itself is
190+
ill-defined. This makes this test less useful than it otherwise might
191+
be.
192+
\end{funcdesc}
193+
194+
\begin{funcdesc}{isNumberType}{o}
195+
Returns true if the object \var{o} represents a number. This is true
196+
for all numeric types implemented in C, and for all instance objects.
197+
\strong{Warning:} There is no reliable way to test if an instance
198+
supports the complete numeric interface since the interface itself is
199+
ill-defined. This makes this test less useful than it otherwise might
200+
be.
201+
\end{funcdesc}
202+
203+
\begin{funcdesc}{isSequenceType}{o}
204+
Returns true if the object \var{o} supports the sequence protocol.
205+
This returns true for all objects which define sequence methods in C,
206+
and for all instance objects. \strong{Warning:} There is no reliable
207+
way to test if an instance supports the complete sequence interface
208+
since the interface itself is ill-defined. This makes this test less
209+
useful than it otherwise might be.
210+
\end{funcdesc}
211+
162212

163213
Example: Build a dictionary that maps the ordinals from \code{0} to
164214
\code{256} to their character equivalents.

0 commit comments

Comments
 (0)