Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Avoid modernization
  • Loading branch information
neonene committed May 21, 2025
commit 8ae6bae6ed4e98818700715e0b23c33455e2e397
26 changes: 14 additions & 12 deletions Doc/extending/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ shortly how it ends up being called)::
spam_system(PyObject *self, PyObject *args)
{
const char *command;
if (!PyArg_ParseTuple(args, "s", &command)) {
int sts;

if (!PyArg_ParseTuple(args, "s", &command))
return NULL;
}
int sts = system(command);
sts = system(command);
return PyLong_FromLong(sts);
}

Expand Down Expand Up @@ -306,10 +307,11 @@ call to :c:func:`PyErr_SetString` as shown below::
spam_system(PyObject *self, PyObject *args)
{
const char *command;
if (!PyArg_ParseTuple(args, "s", &command)) {
int sts;

if (!PyArg_ParseTuple(args, "s", &command))
return NULL;
}
int sts = system(command);
sts = system(command);
if (sts < 0) {
spam_state *state = PyModule_GetState(self);
if (state != NULL) {
Expand All @@ -329,9 +331,8 @@ Back to the Example
Going back to our example function, you should now be able to understand this
statement::

if (!PyArg_ParseTuple(args, "s", &command)) {
if (!PyArg_ParseTuple(args, "s", &command))
return NULL;
}

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

int sts = system(command);
sts = system(command);

Our :func:`!spam.system` function must return the value of :c:data:`!sts` as a
Python object. This is done using the function :c:func:`PyLong_FromLong`. ::
Expand Down Expand Up @@ -1285,10 +1286,11 @@ The function :c:func:`!spam_system` is modified in a trivial way::
spam_system(PyObject *self, PyObject *args)
{
const char *command;
if (!PyArg_ParseTuple(args, "s", &command)) {
int sts;

if (!PyArg_ParseTuple(args, "s", &command))
return NULL;
}
int sts = PySpam_System(command);
sts = PySpam_System(command);
return PyLong_FromLong(sts);
}

Expand Down
6 changes: 2 additions & 4 deletions Doc/extending/newtypes_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,8 @@ implementation provided by the API function :c:func:`PyType_GenericNew`. ::
Everything else in the file should be familiar, except for some code in
:c:func:`!custom_module_exec`::

if (PyType_Ready(&CustomType) < 0) {
if (PyType_Ready(&CustomType) < 0)
return -1;
}

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

if (PyModule_AddObjectRef(mod, "SubList", (PyObject *)&SubListType) < 0) {
return -1;
Expand Down
3 changes: 1 addition & 2 deletions Doc/includes/newtypes/custom.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ static PyTypeObject CustomType = {
static int
custom_module_exec(PyObject *mod)
{
if (PyType_Ready(&CustomType) < 0) {
if (PyType_Ready(&CustomType) < 0)
return -1;
}

if (PyModule_AddObjectRef(mod, "Custom", (PyObject *)&CustomType) < 0) {
return -1;
Expand Down
3 changes: 1 addition & 2 deletions Doc/includes/newtypes/custom2.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ static PyTypeObject CustomType = {
static int
custom_module_exec(PyObject *mod)
{
if (PyType_Ready(&CustomType) < 0) {
if (PyType_Ready(&CustomType) < 0)
return -1;
}

if (PyModule_AddObjectRef(mod, "Custom", (PyObject *)&CustomType) < 0) {
return -1;
Expand Down
3 changes: 1 addition & 2 deletions Doc/includes/newtypes/custom3.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,8 @@ static PyTypeObject CustomType = {
static int
custom_module_exec(PyObject *mod)
{
if (PyType_Ready(&CustomType) < 0) {
if (PyType_Ready(&CustomType) < 0)
return -1;
}

if (PyModule_AddObjectRef(mod, "Custom", (PyObject *)&CustomType) < 0) {
return -1;
Expand Down
3 changes: 1 addition & 2 deletions Doc/includes/newtypes/custom4.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,8 @@ static PyTypeObject CustomType = {
static int
custom_module_exec(PyObject *mod)
{
if (PyType_Ready(&CustomType) < 0) {
if (PyType_Ready(&CustomType) < 0)
return -1;
}

if (PyModule_AddObjectRef(mod, "Custom", (PyObject *)&CustomType) < 0) {
return -1;
Expand Down
3 changes: 1 addition & 2 deletions Doc/includes/newtypes/sublist.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ static int
sublist_module_exec(PyObject *mod)
{
SubListType.tp_base = &PyList_Type;
if (PyType_Ready(&SubListType) < 0) {
if (PyType_Ready(&SubListType) < 0)
return -1;
}

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