Skip to content

Commit 2902a8b

Browse files
committed
Address more review comments
1 parent 0d91185 commit 2902a8b

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

Doc/extending/first-extension-module.rst

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ a system command name.
3636

3737
.. note::
3838

39-
This tutorial uses API that was added in CPython 3.15.
39+
This tutorial uses APIs that were added in CPython 3.15.
4040
To create an extension that's compatible with earlier versions of CPython,
4141
please follow an earlier version of this documentation.
4242

@@ -122,7 +122,7 @@ and test incremental changes as you follow the rest of the text.
122122
If you don't want to use a tool, you can try to run your compiler directly.
123123
The following command should work for many flavors of Linux, and generate
124124
a ``spam.so`` file that you need to put in a directory
125-
in :py:attr:`sys.path`:
125+
on :py:attr:`sys.path`:
126126

127127
.. code-block:: sh
128128
@@ -161,12 +161,11 @@ Be sure to put this, and any other standard library includes, *after*
161161
On some systems, Python may define some pre-processor definitions
162162
that affect the standard headers.
163163

164-
.. tip::
164+
.. note::
165165

166-
The ``<stdlib.h>`` include is technically not necessary.
167-
:file:`Python.h` :ref:`includes several standard header files <capi-system-includes>`
168-
for its own use and for backwards compatibility,
169-
and ``stdlib`` is one of them.
166+
This include is technically not necessary: :file:`Python.h` includes
167+
``stdlib`` and :ref:`several other standard headers <capi-system-includes>`
168+
for its own use.
170169
However, it is good practice to explicitly include what you need.
171170

172171
With the includes in place, compile and import the extension again.
@@ -357,7 +356,10 @@ Add a :c:data:`Py_mod_methods` slot to your a :c:type:`PyMethodDef` array:
357356
:emphasize-lines: 6
358357

359358
Recompile your extension again, and test it.
360-
You should now be able to call the function, and get ``None`` back:
359+
Be sure to restart the Python interpreter, so that ``import spam`` picks
360+
up the new version if the module.
361+
362+
You should now be able to call the function:
361363

362364
.. code-block:: pycon
363365
@@ -367,6 +369,9 @@ You should now be able to call the function, and get ``None`` back:
367369
>>> print(spam.system('whoami'))
368370
None
369371
372+
Note that our ``spam.system`` does not yet run the ``whoami`` command;
373+
it only returns ``None``.
374+
370375

371376
Returning an integer
372377
====================
@@ -396,7 +401,8 @@ To call it, replace the ``Py_RETURN_NONE`` with the following 3 lines:
396401
}
397402
398403
399-
Recompile and run again, and check that the function now returns 3:
404+
Recompile, restart the Python interpreter again,
405+
and check that the function now returns 3:
400406

401407
.. code-block:: pycon
402408
@@ -421,7 +427,7 @@ We expect that it should be a Python string.
421427
In order to use the information in it, we will need
422428
to convert it to a C value --- in this case, a C string (``const char *``).
423429

424-
There's a slight type mismatch here: Python's :c:type:`str` objects store
430+
There's a slight type mismatch here: Python's :py:class:`str` objects store
425431
Unicode text, but C strings are arrays of bytes.
426432
So, we'll need to *encode* the data, and we'll use the UTF-8 encoding for it.
427433
(UTF-8 might not always be correct for system commands, but it's what
@@ -500,7 +506,9 @@ the ``char *`` buffer, and using its result instead of the ``3``:
500506
return result;
501507
}
502508
503-
Compile your module, and test:
509+
Compile your module, restart Python, and test.
510+
This time, you should see your username -- the output of the ``whoami``
511+
system command:
504512

505513
.. code-block:: pycon
506514

0 commit comments

Comments
 (0)