mirror of
https://github.com/python/cpython.git
synced 2025-10-27 16:57:08 +00:00
Add optional docstrings to member descriptors. For backwards
compatibility, this required all places where an array of "struct memberlist" structures was declared that is referenced from a type's tp_members slot to change the type of the structure to PyMemberDef; "struct memberlist" is now only used by old code that still calls PyMember_Get/Set. The code in PyObject_GenericGetAttr/SetAttr now calls the new APIs PyMember_GetOne/SetOne, which take a PyMemberDef argument. As examples, I added actual docstrings to the attributes of a few types: file, complex, instance method, super, and xxsubtype.spamlist. Also converted the symtable to new style getattr.
This commit is contained in:
parent
e0af35eb69
commit
6f7993765a
17 changed files with 313 additions and 251 deletions
|
|
@ -106,7 +106,7 @@ ste_dealloc(PySymtableEntryObject *ste)
|
|||
|
||||
#define OFF(x) offsetof(PySymtableEntryObject, x)
|
||||
|
||||
static struct memberlist ste_memberlist[] = {
|
||||
static PyMemberDef ste_memberlist[] = {
|
||||
{"id", T_OBJECT, OFF(ste_id), READONLY},
|
||||
{"name", T_OBJECT, OFF(ste_name), READONLY},
|
||||
{"symbols", T_OBJECT, OFF(ste_symbols), READONLY},
|
||||
|
|
@ -119,12 +119,6 @@ static struct memberlist ste_memberlist[] = {
|
|||
{NULL}
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
ste_getattr(PySymtableEntryObject *ste, char *name)
|
||||
{
|
||||
return PyMember_Get((char *)ste, ste_memberlist, name);
|
||||
}
|
||||
|
||||
PyTypeObject PySymtableEntry_Type = {
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0,
|
||||
|
|
@ -133,7 +127,7 @@ PyTypeObject PySymtableEntry_Type = {
|
|||
0,
|
||||
(destructor)ste_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
(getattrfunc)ste_getattr, /* tp_getattr */
|
||||
0, /* tp_getattr */
|
||||
0, /* tp_setattr */
|
||||
0, /* tp_compare */
|
||||
(reprfunc)ste_repr, /* tp_repr */
|
||||
|
|
@ -143,9 +137,26 @@ PyTypeObject PySymtableEntry_Type = {
|
|||
0, /* tp_hash */
|
||||
0, /* tp_call */
|
||||
0, /* tp_str */
|
||||
0, /* tp_getattro */
|
||||
PyObject_GenericGetAttr, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
||||
0, /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
ste_memberlist, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
0, /* tp_new */
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue