Skip to content

Commit 8ae6bae

Browse files
committed
Avoid modernization
1 parent 97eae13 commit 8ae6bae

File tree

7 files changed

+21
-26
lines changed

7 files changed

+21
-26
lines changed

Doc/extending/extending.rst

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ shortly how it ends up being called)::
9595
spam_system(PyObject *self, PyObject *args)
9696
{
9797
const char *command;
98-
if (!PyArg_ParseTuple(args, "s", &command)) {
98+
int sts;
99+
100+
if (!PyArg_ParseTuple(args, "s", &command))
99101
return NULL;
100-
}
101-
int sts = system(command);
102+
sts = system(command);
102103
return PyLong_FromLong(sts);
103104
}
104105

@@ -306,10 +307,11 @@ call to :c:func:`PyErr_SetString` as shown below::
306307
spam_system(PyObject *self, PyObject *args)
307308
{
308309
const char *command;
309-
if (!PyArg_ParseTuple(args, "s", &command)) {
310+
int sts;
311+
312+
if (!PyArg_ParseTuple(args, "s", &command))
310313
return NULL;
311-
}
312-
int sts = system(command);
314+
sts = system(command);
313315
if (sts < 0) {
314316
spam_state *state = PyModule_GetState(self);
315317
if (state != NULL) {
@@ -329,9 +331,8 @@ Back to the Example
329331
Going back to our example function, you should now be able to understand this
330332
statement::
331333

332-
if (!PyArg_ParseTuple(args, "s", &command)) {
334+
if (!PyArg_ParseTuple(args, "s", &command))
333335
return NULL;
334-
}
335336

336337
It returns ``NULL`` (the error indicator for functions returning object pointers)
337338
if an error is detected in the argument list, relying on the exception set by
@@ -344,7 +345,7 @@ the variable :c:data:`!command` should properly be declared as ``const char
344345
The next statement is a call to the Unix function :c:func:`system`, passing it
345346
the string we just got from :c:func:`PyArg_ParseTuple`::
346347

347-
int sts = system(command);
348+
sts = system(command);
348349

349350
Our :func:`!spam.system` function must return the value of :c:data:`!sts` as a
350351
Python object. This is done using the function :c:func:`PyLong_FromLong`. ::
@@ -1285,10 +1286,11 @@ The function :c:func:`!spam_system` is modified in a trivial way::
12851286
spam_system(PyObject *self, PyObject *args)
12861287
{
12871288
const char *command;
1288-
if (!PyArg_ParseTuple(args, "s", &command)) {
1289+
int sts;
1290+
1291+
if (!PyArg_ParseTuple(args, "s", &command))
12891292
return NULL;
1290-
}
1291-
int sts = PySpam_System(command);
1293+
sts = PySpam_System(command);
12921294
return PyLong_FromLong(sts);
12931295
}
12941296

Doc/extending/newtypes_tutorial.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,8 @@ implementation provided by the API function :c:func:`PyType_GenericNew`. ::
173173
Everything else in the file should be familiar, except for some code in
174174
:c:func:`!custom_module_exec`::
175175

176-
if (PyType_Ready(&CustomType) < 0) {
176+
if (PyType_Ready(&CustomType) < 0)
177177
return -1;
178-
}
179178

180179
This initializes the :class:`!Custom` type, filling in a number of members
181180
to the appropriate default values, including :c:member:`~PyObject.ob_type` that we initially
@@ -882,9 +881,8 @@ function::
882881
sublist_module_exec(PyObject *mod)
883882
{
884883
SubListType.tp_base = &PyList_Type;
885-
if (PyType_Ready(&SubListType) < 0) {
884+
if (PyType_Ready(&SubListType) < 0)
886885
return -1;
887-
}
888886

889887
if (PyModule_AddObjectRef(mod, "SubList", (PyObject *)&SubListType) < 0) {
890888
return -1;

Doc/includes/newtypes/custom.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ static PyTypeObject CustomType = {
1919
static int
2020
custom_module_exec(PyObject *mod)
2121
{
22-
if (PyType_Ready(&CustomType) < 0) {
22+
if (PyType_Ready(&CustomType) < 0)
2323
return -1;
24-
}
2524

2625
if (PyModule_AddObjectRef(mod, "Custom", (PyObject *)&CustomType) < 0) {
2726
return -1;

Doc/includes/newtypes/custom2.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ static PyTypeObject CustomType = {
109109
static int
110110
custom_module_exec(PyObject *mod)
111111
{
112-
if (PyType_Ready(&CustomType) < 0) {
112+
if (PyType_Ready(&CustomType) < 0)
113113
return -1;
114-
}
115114

116115
if (PyModule_AddObjectRef(mod, "Custom", (PyObject *)&CustomType) < 0) {
117116
return -1;

Doc/includes/newtypes/custom3.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,8 @@ static PyTypeObject CustomType = {
154154
static int
155155
custom_module_exec(PyObject *mod)
156156
{
157-
if (PyType_Ready(&CustomType) < 0) {
157+
if (PyType_Ready(&CustomType) < 0)
158158
return -1;
159-
}
160159

161160
if (PyModule_AddObjectRef(mod, "Custom", (PyObject *)&CustomType) < 0) {
162161
return -1;

Doc/includes/newtypes/custom4.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,8 @@ static PyTypeObject CustomType = {
173173
static int
174174
custom_module_exec(PyObject *mod)
175175
{
176-
if (PyType_Ready(&CustomType) < 0) {
176+
if (PyType_Ready(&CustomType) < 0)
177177
return -1;
178-
}
179178

180179
if (PyModule_AddObjectRef(mod, "Custom", (PyObject *)&CustomType) < 0) {
181180
return -1;

Doc/includes/newtypes/sublist.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ static int
4545
sublist_module_exec(PyObject *mod)
4646
{
4747
SubListType.tp_base = &PyList_Type;
48-
if (PyType_Ready(&SubListType) < 0) {
48+
if (PyType_Ready(&SubListType) < 0)
4949
return -1;
50-
}
5150

5251
if (PyModule_AddObjectRef(mod, "SubList", (PyObject *)&SubListType) < 0) {
5352
return -1;

0 commit comments

Comments
 (0)