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

Skip to content

Commit 47fe5c0

Browse files
committed
Issue #12672: fix code samples in extending/newtypes.html for PEP-7 compliance
1 parent ff3d3e4 commit 47fe5c0

4 files changed

Lines changed: 85 additions & 93 deletions

File tree

Doc/extending/newtypes.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,18 +289,16 @@ strings, so we provide a new method::
289289
self = (Noddy *)type->tp_alloc(type, 0);
290290
if (self != NULL) {
291291
self->first = PyString_FromString("");
292-
if (self->first == NULL)
293-
{
292+
if (self->first == NULL) {
294293
Py_DECREF(self);
295294
return NULL;
296-
}
295+
}
297296

298297
self->last = PyString_FromString("");
299-
if (self->last == NULL)
300-
{
298+
if (self->last == NULL) {
301299
Py_DECREF(self);
302300
return NULL;
303-
}
301+
}
304302

305303
self->number = 0;
306304
}

Doc/includes/noddy2.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,16 @@ Noddy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2424
self = (Noddy *)type->tp_alloc(type, 0);
2525
if (self != NULL) {
2626
self->first = PyUnicode_FromString("");
27-
if (self->first == NULL)
28-
{
27+
if (self->first == NULL) {
2928
Py_DECREF(self);
3029
return NULL;
31-
}
32-
30+
}
31+
3332
self->last = PyUnicode_FromString("");
34-
if (self->last == NULL)
35-
{
33+
if (self->last == NULL) {
3634
Py_DECREF(self);
3735
return NULL;
38-
}
36+
}
3937

4038
self->number = 0;
4139
}
@@ -50,10 +48,10 @@ Noddy_init(Noddy *self, PyObject *args, PyObject *kwds)
5048

5149
static char *kwlist[] = {"first", "last", "number", NULL};
5250

53-
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOi", kwlist,
54-
&first, &last,
51+
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOi", kwlist,
52+
&first, &last,
5553
&self->number))
56-
return -1;
54+
return -1;
5755

5856
if (first) {
5957
tmp = self->first;
@@ -111,7 +109,7 @@ Noddy_name(Noddy* self)
111109

112110
result = PyUnicode_Format(format, args);
113111
Py_DECREF(args);
114-
112+
115113
return result;
116114
}
117115

@@ -145,12 +143,12 @@ static PyTypeObject NoddyType = {
145143
Py_TPFLAGS_DEFAULT |
146144
Py_TPFLAGS_BASETYPE, /* tp_flags */
147145
"Noddy objects", /* tp_doc */
148-
0, /* tp_traverse */
149-
0, /* tp_clear */
150-
0, /* tp_richcompare */
151-
0, /* tp_weaklistoffset */
152-
0, /* tp_iter */
153-
0, /* tp_iternext */
146+
0, /* tp_traverse */
147+
0, /* tp_clear */
148+
0, /* tp_richcompare */
149+
0, /* tp_weaklistoffset */
150+
0, /* tp_iter */
151+
0, /* tp_iternext */
154152
Noddy_methods, /* tp_methods */
155153
Noddy_members, /* tp_members */
156154
0, /* tp_getset */
@@ -173,7 +171,7 @@ static PyModuleDef noddy2module = {
173171
};
174172

175173
PyMODINIT_FUNC
176-
PyInit_noddy2(void)
174+
PyInit_noddy2(void)
177175
{
178176
PyObject* m;
179177

Doc/includes/noddy3.c

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,16 @@ Noddy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2424
self = (Noddy *)type->tp_alloc(type, 0);
2525
if (self != NULL) {
2626
self->first = PyUnicode_FromString("");
27-
if (self->first == NULL)
28-
{
27+
if (self->first == NULL) {
2928
Py_DECREF(self);
3029
return NULL;
31-
}
32-
30+
}
31+
3332
self->last = PyUnicode_FromString("");
34-
if (self->last == NULL)
35-
{
33+
if (self->last == NULL) {
3634
Py_DECREF(self);
3735
return NULL;
38-
}
36+
}
3937

4038
self->number = 0;
4139
}
@@ -50,10 +48,10 @@ Noddy_init(Noddy *self, PyObject *args, PyObject *kwds)
5048

5149
static char *kwlist[] = {"first", "last", "number", NULL};
5250

53-
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|SSi", kwlist,
54-
&first, &last,
51+
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|SSi", kwlist,
52+
&first, &last,
5553
&self->number))
56-
return -1;
54+
return -1;
5755

5856
if (first) {
5957
tmp = self->first;
@@ -88,22 +86,22 @@ Noddy_getfirst(Noddy *self, void *closure)
8886
static int
8987
Noddy_setfirst(Noddy *self, PyObject *value, void *closure)
9088
{
91-
if (value == NULL) {
92-
PyErr_SetString(PyExc_TypeError, "Cannot delete the first attribute");
93-
return -1;
94-
}
95-
96-
if (! PyUnicode_Check(value)) {
97-
PyErr_SetString(PyExc_TypeError,
98-
"The first attribute value must be a string");
99-
return -1;
100-
}
101-
102-
Py_DECREF(self->first);
103-
Py_INCREF(value);
104-
self->first = value;
105-
106-
return 0;
89+
if (value == NULL) {
90+
PyErr_SetString(PyExc_TypeError, "Cannot delete the first attribute");
91+
return -1;
92+
}
93+
94+
if (! PyUnicode_Check(value)) {
95+
PyErr_SetString(PyExc_TypeError,
96+
"The first attribute value must be a string");
97+
return -1;
98+
}
99+
100+
Py_DECREF(self->first);
101+
Py_INCREF(value);
102+
self->first = value;
103+
104+
return 0;
107105
}
108106

109107
static PyObject *
@@ -116,30 +114,30 @@ Noddy_getlast(Noddy *self, void *closure)
116114
static int
117115
Noddy_setlast(Noddy *self, PyObject *value, void *closure)
118116
{
119-
if (value == NULL) {
120-
PyErr_SetString(PyExc_TypeError, "Cannot delete the last attribute");
121-
return -1;
122-
}
123-
124-
if (! PyUnicode_Check(value)) {
125-
PyErr_SetString(PyExc_TypeError,
126-
"The last attribute value must be a string");
127-
return -1;
128-
}
129-
130-
Py_DECREF(self->last);
131-
Py_INCREF(value);
132-
self->last = value;
133-
134-
return 0;
117+
if (value == NULL) {
118+
PyErr_SetString(PyExc_TypeError, "Cannot delete the last attribute");
119+
return -1;
120+
}
121+
122+
if (! PyUnicode_Check(value)) {
123+
PyErr_SetString(PyExc_TypeError,
124+
"The last attribute value must be a string");
125+
return -1;
126+
}
127+
128+
Py_DECREF(self->last);
129+
Py_INCREF(value);
130+
self->last = value;
131+
132+
return 0;
135133
}
136134

137135
static PyGetSetDef Noddy_getseters[] = {
138-
{"first",
136+
{"first",
139137
(getter)Noddy_getfirst, (setter)Noddy_setfirst,
140138
"first name",
141139
NULL},
142-
{"last",
140+
{"last",
143141
(getter)Noddy_getlast, (setter)Noddy_setlast,
144142
"last name",
145143
NULL},
@@ -164,7 +162,7 @@ Noddy_name(Noddy* self)
164162

165163
result = PyUnicode_Format(format, args);
166164
Py_DECREF(args);
167-
165+
168166
return result;
169167
}
170168

@@ -198,12 +196,12 @@ static PyTypeObject NoddyType = {
198196
Py_TPFLAGS_DEFAULT |
199197
Py_TPFLAGS_BASETYPE, /* tp_flags */
200198
"Noddy objects", /* tp_doc */
201-
0, /* tp_traverse */
202-
0, /* tp_clear */
203-
0, /* tp_richcompare */
204-
0, /* tp_weaklistoffset */
205-
0, /* tp_iter */
206-
0, /* tp_iternext */
199+
0, /* tp_traverse */
200+
0, /* tp_clear */
201+
0, /* tp_richcompare */
202+
0, /* tp_weaklistoffset */
203+
0, /* tp_iter */
204+
0, /* tp_iternext */
207205
Noddy_methods, /* tp_methods */
208206
Noddy_members, /* tp_members */
209207
Noddy_getseters, /* tp_getset */
@@ -226,7 +224,7 @@ static PyModuleDef noddy3module = {
226224
};
227225

228226
PyMODINIT_FUNC
229-
PyInit_noddy3(void)
227+
PyInit_noddy3(void)
230228
{
231229
PyObject* m;
232230

Doc/includes/noddy4.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Noddy_traverse(Noddy *self, visitproc visit, void *arg)
2727
return 0;
2828
}
2929

30-
static int
30+
static int
3131
Noddy_clear(Noddy *self)
3232
{
3333
PyObject *tmp;
@@ -58,18 +58,16 @@ Noddy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
5858
self = (Noddy *)type->tp_alloc(type, 0);
5959
if (self != NULL) {
6060
self->first = PyUnicode_FromString("");
61-
if (self->first == NULL)
62-
{
61+
if (self->first == NULL) {
6362
Py_DECREF(self);
6463
return NULL;
65-
}
66-
64+
}
65+
6766
self->last = PyUnicode_FromString("");
68-
if (self->last == NULL)
69-
{
67+
if (self->last == NULL) {
7068
Py_DECREF(self);
7169
return NULL;
72-
}
70+
}
7371

7472
self->number = 0;
7573
}
@@ -84,10 +82,10 @@ Noddy_init(Noddy *self, PyObject *args, PyObject *kwds)
8482

8583
static char *kwlist[] = {"first", "last", "number", NULL};
8684

87-
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOi", kwlist,
88-
&first, &last,
85+
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOi", kwlist,
86+
&first, &last,
8987
&self->number))
90-
return -1;
88+
return -1;
9189

9290
if (first) {
9391
tmp = self->first;
@@ -145,7 +143,7 @@ Noddy_name(Noddy* self)
145143

146144
result = PyUnicode_Format(format, args);
147145
Py_DECREF(args);
148-
146+
149147
return result;
150148
}
151149

@@ -182,10 +180,10 @@ static PyTypeObject NoddyType = {
182180
"Noddy objects", /* tp_doc */
183181
(traverseproc)Noddy_traverse, /* tp_traverse */
184182
(inquiry)Noddy_clear, /* tp_clear */
185-
0, /* tp_richcompare */
186-
0, /* tp_weaklistoffset */
187-
0, /* tp_iter */
188-
0, /* tp_iternext */
183+
0, /* tp_richcompare */
184+
0, /* tp_weaklistoffset */
185+
0, /* tp_iter */
186+
0, /* tp_iternext */
189187
Noddy_methods, /* tp_methods */
190188
Noddy_members, /* tp_members */
191189
0, /* tp_getset */
@@ -208,7 +206,7 @@ static PyModuleDef noddy4module = {
208206
};
209207

210208
PyMODINIT_FUNC
211-
PyInit_noddy4(void)
209+
PyInit_noddy4(void)
212210
{
213211
PyObject* m;
214212

0 commit comments

Comments
 (0)