diff options
author | Fred Drake <fdrake@acm.org> | 2002-03-28 05:33:33 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2002-03-28 05:33:33 (GMT) |
commit | 7bf9715a8b794cb743fdac97a9014102985a3dd3 (patch) | |
tree | 41771e7698486015d70b420b8f7df6a0febd8225 /Doc/api | |
parent | ed6a886d9fd86ba197a679cbfaccdab1cde8db0d (diff) | |
download | cpython-7bf9715a8b794cb743fdac97a9014102985a3dd3.zip cpython-7bf9715a8b794cb743fdac97a9014102985a3dd3.tar.gz cpython-7bf9715a8b794cb743fdac97a9014102985a3dd3.tar.bz2 |
Introduce two new flag bits that can be set in a PyMethodDef method
descriptor, as used for the tp_methods slot of a type. These new flag
bits are both optional, and mutually exclusive. Most methods will not
use either. These flags are used to create special method types which
exist in the same namespace as normal methods without having to use
tedious construction code to insert the new special method objects in
the type's tp_dict after PyType_Ready() has been called.
If METH_CLASS is specified, the method will represent a class method
like that returned by the classmethod() built-in.
If METH_STATIC is specified, the method will represent a static method
like that returned by the staticmethod() built-in.
These flags may not be used in the PyMethodDef table for modules since
these special method types are not meaningful in that case; a
ValueError will be raised if these flags are found in that context.
Diffstat (limited to 'Doc/api')
-rw-r--r-- | Doc/api/newtypes.tex | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/Doc/api/newtypes.tex b/Doc/api/newtypes.tex index 8ab8e3c..b4f90e5 100644 --- a/Doc/api/newtypes.tex +++ b/Doc/api/newtypes.tex @@ -152,8 +152,12 @@ a cast in the method table. Even though \ctype{PyCFunction} defines the first parameter as \ctype{PyObject*}, it is common that the method implementation uses a the specific C type of the \var{self} object. -The flags can have the following values. Only \constant{METH_VARARGS} -and \constant{METH_KEYWORDS} can be combined; the others can't. +The \member{ml_flags} field is a bitfield which can include the +following flags. The individual flags indicate either a calling +convention or a binding convention. Of the calling convention flags, +only \constant{METH_VARARGS} and \constant{METH_KEYWORDS} can be +combined. Any of the calling convention flags can be combined with a +binding flag. \begin{datadesc}{METH_VARARGS} This is the typical calling convention, where the methods have the @@ -203,6 +207,30 @@ and \constant{METH_KEYWORDS} can be combined; the others can't. argument. \end{datadesc} +These two constants are not used to indicate the calling convention +but the binding when use with methods of classes. These may not be +used for functions defined for modules. At most one of these flags +may be set for any given method. + +\begin{datadesc}{METH_CLASS} + The method will be passed the type object as the first parameter + rather than an instance of the type. This is used to create + \emph{class methods}, similar to what is created when using the + \function{classmethod()}\bifuncindex{classmethod} built-in + function. + \versionadded{2.3} +\end{datadesc} + +\begin{datadesc}{METH_STATIC} + The method will be passed \NULL{} as the first parameter rather than + an instance of the type. This is used to create \emph{static + methods}, similar to what is created when using the + \function{staticmethod()}\bifuncindex{staticmethod} built-in + function. + \versionadded{2.3} +\end{datadesc} + + \begin{cfuncdesc}{PyObject*}{Py_FindMethod}{PyMethodDef table[], PyObject *ob, char *name} Return a bound method object for an extension type implemented in |