mirror of https://github.com/python/cpython
Added documentation for PyObject_IsInstance() and PyObject_IsSubclass().
This commit is contained in:
parent
fc369f21d5
commit
58c8f9f631
|
@ -1493,6 +1493,42 @@ the equivalent of the Python expression \samp{unistr(\var{o})}.
|
|||
Called by the \function{unistr()}\bifuncindex{unistr} built-in function.
|
||||
\end{cfuncdesc}
|
||||
|
||||
\begin{cfuncdesc}{int}{PyObject_IsInstance}{PyObject *inst, PyObject *cls}
|
||||
Return \code{1} if \var{inst} is an instance of the class \var{cls} or
|
||||
a subclass of \var{cls}. If \var{cls} is a type object rather than a
|
||||
class object, \cfunction{PyObject_IsInstance()} returns \code{1} if
|
||||
\var{inst} is of type \var{cls}. If \var{inst} is not a class
|
||||
instance and \var{cls} is neither a type object or class object,
|
||||
\var{inst} must have a \member{__class__} attribute --- the class
|
||||
relationship of the value of that attribute with \var{cls} will be
|
||||
used to determine the result of this function.
|
||||
\versionadded{2.1}
|
||||
\end{cfuncdesc}
|
||||
|
||||
Subclass determination is done in a fairly straightforward way, but
|
||||
includes a wrinkle that implementors of extensions to the class system
|
||||
may want to be aware of. If \class{A} and \class{B} are class
|
||||
objects, \class{B} is a subclass of \class{A} if it inherits from
|
||||
\class{A} either directly or indirectly. If either is not a class
|
||||
object, a more general mechanism is used to determine the class
|
||||
relationship of the two objects. When testing if \var{B} is a
|
||||
subclass of \var{A}, if \var{A} is \var{B},
|
||||
\cfunction{PyObject_IsSubclass()} returns true. If \var{A} and
|
||||
\var{B} are different objects, \var{B}'s \member{__bases__} attribute
|
||||
is searched in a depth-first fashion for \var{A} --- the presence of
|
||||
the \member{__bases__} attribute is considered sufficient for this
|
||||
determination.
|
||||
|
||||
\begin{cfuncdesc}{int}{PyObject_IsSubclass}{PyObject *derived,
|
||||
PyObject *cls}
|
||||
Returns \code{1} if the class \var{derived} is identical to or derived
|
||||
from the class \var{cls}, otherwise returns \code{0}. In case of an
|
||||
error, returns \code{-1}. If either \var{derived} or \var{cls} is not
|
||||
an actual class object, this function uses the generic algorithm
|
||||
described above.
|
||||
\versionadded{2.1}
|
||||
\end{cfuncdesc}
|
||||
|
||||
|
||||
\begin{cfuncdesc}{int}{PyCallable_Check}{PyObject *o}
|
||||
Determine if the object \var{o} is callable. Return \code{1} if the
|
||||
|
|
Loading…
Reference in New Issue