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

Skip to content

Commit 87ce6d7

Browse files
committed
#3247: get rid of Py_FindMethods
Remove references in documentation; also rewrite a paragraph that looked off-topic to me.
1 parent 1f900f1 commit 87ce6d7

3 files changed

Lines changed: 12 additions & 32 deletions

File tree

Doc/c-api/structures.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,3 @@ definition with the same method name.
198198
object and will co-exist with the slot. This is helpful because calls to
199199
PyCFunctions are optimized more than wrapper object calls.
200200

201-
202-
.. cfunction:: PyObject* Py_FindMethod(PyMethodDef table[], PyObject *ob, char *name)
203-
204-
Return a bound method object for an extension type implemented in C. This can
205-
be useful in the implementation of a :attr:`tp_getattro` or :attr:`tp_getattr`
206-
handler that does not use the :cfunc:`PyObject_GenericGetAttr` function.

Doc/data/refcounts.dat

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,11 +1686,6 @@ Py_FdIsInteractive:char*:filename::
16861686

16871687
Py_Finalize:void:::
16881688

1689-
Py_FindMethod:PyObject*::+1:
1690-
Py_FindMethod:PyMethodDef[]:methods::
1691-
Py_FindMethod:PyObject*:self:+1:
1692-
Py_FindMethod:char*:name::
1693-
16941689
Py_GetBuildInfoconst:char*:::
16951690

16961691
Py_GetCompilerconst:char*:::

Doc/extending/newtypes.rst

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,8 +1074,8 @@ sense for the implementation's convenience. ::
10741074
getattrfunc tp_getattr; /* char * version */
10751075
setattrfunc tp_setattr;
10761076
/* ... */
1077-
getattrofunc tp_getattrofunc; /* PyObject * version */
1078-
setattrofunc tp_setattrofunc;
1077+
getattrofunc tp_getattro; /* PyObject * version */
1078+
setattrofunc tp_setattro;
10791079

10801080
If accessing attributes of an object is always a simple operation (this will be
10811081
explained shortly), there are generic implementations which can be used to
@@ -1204,37 +1204,28 @@ For simplicity, only the :ctype:`char\*` version will be demonstrated here; the
12041204
type of the name parameter is the only difference between the :ctype:`char\*`
12051205
and :ctype:`PyObject\*` flavors of the interface. This example effectively does
12061206
the same thing as the generic example above, but does not use the generic
1207-
support added in Python 2.2. The value in showing this is two-fold: it
1208-
demonstrates how basic attribute management can be done in a way that is
1209-
portable to older versions of Python, and explains how the handler functions are
1207+
support added in Python 2.2. It explains how the handler functions are
12101208
called, so that if you do need to extend their functionality, you'll understand
12111209
what needs to be done.
12121210

12131211
The :attr:`tp_getattr` handler is called when the object requires an attribute
12141212
look-up. It is called in the same situations where the :meth:`__getattr__`
12151213
method of a class would be called.
12161214

1217-
A likely way to handle this is (1) to implement a set of functions (such as
1218-
:cfunc:`newdatatype_getSize` and :cfunc:`newdatatype_setSize` in the example
1219-
below), (2) provide a method table listing these functions, and (3) provide a
1220-
getattr function that returns the result of a lookup in that table. The method
1221-
table uses the same structure as the :attr:`tp_methods` field of the type
1222-
object.
1223-
12241215
Here is an example::
12251216

1226-
static PyMethodDef newdatatype_methods[] = {
1227-
{"getSize", (PyCFunction)newdatatype_getSize, METH_VARARGS,
1228-
"Return the current size."},
1229-
{"setSize", (PyCFunction)newdatatype_setSize, METH_VARARGS,
1230-
"Set the size."},
1231-
{NULL, NULL, 0, NULL} /* sentinel */
1232-
};
1233-
12341217
static PyObject *
12351218
newdatatype_getattr(newdatatypeobject *obj, char *name)
12361219
{
1237-
return Py_FindMethod(newdatatype_methods, (PyObject *)obj, name);
1220+
if (strcmp(name, "data") == 0)
1221+
{
1222+
return PyInt_FromLong(obj->data);
1223+
}
1224+
1225+
PyErr_Format(PyExc_AttributeError,
1226+
"'%.50s' object has no attribute '%.400s'",
1227+
tp->tp_name, name);
1228+
return NULL;
12381229
}
12391230

12401231
The :attr:`tp_setattr` handler is called when the :meth:`__setattr__` or

0 commit comments

Comments
 (0)