Skip to content

Commit dae60d0

Browse files
committed
Merge remote-tracking branch 'original/main'
2 parents 5224176 + 7a6cc3e commit dae60d0

File tree

154 files changed

+1933
-1997
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+1933
-1997
lines changed

Doc/c-api/exceptions.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,21 @@ For convenience, some of these functions will always return a
222222
223223
.. c:function:: PyObject* PyErr_SetFromWindowsErrWithFilename(int ierr, const char *filename)
224224
225-
Similar to :c:func:`PyErr_SetFromWindowsErrWithFilenameObject`, but the
226-
filename is given as a C string. *filename* is decoded from the filesystem
227-
encoding (:func:`os.fsdecode`).
225+
Similar to :c:func:`PyErr_SetFromWindowsErr`, with the additional behavior
226+
that if *filename* is not ``NULL``, it is decoded from the filesystem
227+
encoding (:func:`os.fsdecode`) and passed to the constructor of
228+
:exc:`OSError` as a third parameter to be used to define the
229+
:attr:`!filename` attribute of the exception instance.
228230
229231
.. availability:: Windows.
230232
231233
232234
.. c:function:: PyObject* PyErr_SetExcFromWindowsErrWithFilenameObject(PyObject *type, int ierr, PyObject *filename)
233235
234-
Similar to :c:func:`PyErr_SetFromWindowsErrWithFilenameObject`, with an
235-
additional parameter specifying the exception type to be raised.
236+
Similar to :c:func:`PyErr_SetExcFromWindowsErr`, with the additional behavior
237+
that if *filename* is not ``NULL``, it is passed to the constructor of
238+
:exc:`OSError` as a third parameter to be used to define the
239+
:attr:`!filename` attribute of the exception instance.
236240
237241
.. availability:: Windows.
238242

Doc/c-api/init_config.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ PyWideStringList
8282
If *length* is non-zero, *items* must be non-``NULL`` and all strings must be
8383
non-``NULL``.
8484

85+
.. c:namespace:: NULL
86+
8587
Methods:
8688

8789
.. c:function:: PyStatus PyWideStringList_Append(PyWideStringList *list, const wchar_t *item)
@@ -101,6 +103,8 @@ PyWideStringList
101103
102104
Python must be preinitialized to call this function.
103105
106+
.. c:namespace:: PyWideStringList
107+
104108
Structure fields:
105109
106110
.. c:member:: Py_ssize_t length

Doc/c-api/module.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ The available slot types are:
338338
The *value* pointer of this slot must point to a function of the signature:
339339
340340
.. c:function:: PyObject* create_module(PyObject *spec, PyModuleDef *def)
341+
:noindex:
341342
342343
The function receives a :py:class:`~importlib.machinery.ModuleSpec`
343344
instance, as defined in :PEP:`451`, and the module definition.
@@ -372,6 +373,7 @@ The available slot types are:
372373
The signature of the function is:
373374
374375
.. c:function:: int exec_module(PyObject* module)
376+
:noindex:
375377
376378
If multiple ``Py_mod_exec`` slots are specified, they are processed in the
377379
order they appear in the *m_slots* array.
@@ -380,6 +382,8 @@ The available slot types are:
380382
381383
Specifies one of the following values:
382384
385+
.. c:namespace:: NULL
386+
383387
.. c:macro:: Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED
384388
385389
The module does not support being imported in subinterpreters.

Doc/c-api/typeobj.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
14031403
are allowed to be removed even if the instance is still alive).
14041404

14051405
Note that :c:func:`Py_VISIT` requires the *visit* and *arg* parameters to
1406-
:c:func:`local_traverse` to have these specific names; don't name them just
1406+
:c:func:`!local_traverse` to have these specific names; don't name them just
14071407
anything.
14081408

14091409
Instances of :ref:`heap-allocated types <heap-types>` hold a reference to

Doc/c-api/unicode.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,7 @@ the user settings on the machine running the codec.
12921292
12931293
Encode the Unicode object using the specified code page and return a Python
12941294
bytes object. Return ``NULL`` if an exception was raised by the codec. Use
1295-
:c:macro:`CP_ACP` code page to get the MBCS encoder.
1295+
:c:macro:`!CP_ACP` code page to get the MBCS encoder.
12961296
12971297
.. versionadded:: 3.3
12981298

Doc/extending/newtypes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ have an associated doc string simply by providing the text in the table. An
298298
application can use the introspection API to retrieve the descriptor from the
299299
class object, and get the doc string using its :attr:`__doc__` attribute.
300300

301-
As with the :c:member:`~PyTypeObject.tp_methods` table, a sentinel entry with a :c:member:`~PyMethodDef.name` value
301+
As with the :c:member:`~PyTypeObject.tp_methods` table, a sentinel entry with a :c:member:`~PyMethodDef.ml_name` value
302302
of ``NULL`` is required.
303303

304304
.. XXX Descriptors need to be explained in more detail somewhere, but not here.

Doc/extending/newtypes_tutorial.rst

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extension module :mod:`!custom`:
4545
allows defining heap-allocated extension types using the
4646
:c:func:`PyType_FromSpec` function, which isn't covered in this tutorial.
4747

48-
.. literalinclude:: ../includes/custom.c
48+
.. literalinclude:: ../includes/newtypes/custom.c
4949

5050
Now that's quite a bit to take in at once, but hopefully bits will seem familiar
5151
from the previous chapter. This file defines three things:
@@ -194,36 +194,32 @@ This adds the type to the module dictionary. This allows us to create
194194
>>> mycustom = custom.Custom()
195195
196196
That's it! All that remains is to build it; put the above code in a file called
197-
:file:`custom.c` and:
197+
:file:`custom.c`,
198+
199+
.. literalinclude:: ../includes/newtypes/pyproject.toml
200+
201+
in a file called :file:`pyproject.toml`, and
198202

199203
.. code-block:: python
200204
201-
from distutils.core import setup, Extension
202-
setup(name="custom", version="1.0",
203-
ext_modules=[Extension("custom", ["custom.c"])])
205+
from setuptools import Extension, setup
206+
setup(ext_modules=[Extension("custom", ["custom.c"])])
204207
205208
in a file called :file:`setup.py`; then typing
206209

207210
.. code-block:: shell-session
208211
209-
$ python setup.py build
212+
$ python -m pip install .
210213
211-
at a shell should produce a file :file:`custom.so` in a subdirectory; move to
212-
that directory and fire up Python --- you should be able to ``import custom`` and
213-
play around with Custom objects.
214+
in a shell should produce a file :file:`custom.so` in a subdirectory
215+
and install it; now fire up Python --- you should be able to ``import custom``
216+
and play around with ``Custom`` objects.
214217

215218
That wasn't so hard, was it?
216219

217220
Of course, the current Custom type is pretty uninteresting. It has no data and
218221
doesn't do anything. It can't even be subclassed.
219222

220-
.. note::
221-
While this documentation showcases the standard :mod:`!distutils` module
222-
for building C extensions, it is recommended in real-world use cases to
223-
use the newer and better-maintained ``setuptools`` library. Documentation
224-
on how to do this is out of scope for this document and can be found in
225-
the `Python Packaging User's Guide <https://packaging.python.org/tutorials/distributing-packages/>`_.
226-
227223

228224
Adding data and methods to the Basic example
229225
============================================
@@ -232,7 +228,7 @@ Let's extend the basic example to add some data and methods. Let's also make
232228
the type usable as a base class. We'll create a new module, :mod:`!custom2` that
233229
adds these capabilities:
234230

235-
.. literalinclude:: ../includes/custom2.c
231+
.. literalinclude:: ../includes/newtypes/custom2.c
236232

237233

238234
This version of the module has a number of changes.
@@ -514,17 +510,21 @@ We rename :c:func:`!PyInit_custom` to :c:func:`!PyInit_custom2`, update the
514510
module name in the :c:type:`PyModuleDef` struct, and update the full class
515511
name in the :c:type:`PyTypeObject` struct.
516512

517-
Finally, we update our :file:`setup.py` file to build the new module:
513+
Finally, we update our :file:`setup.py` file to include the new module,
518514

519515
.. code-block:: python
520516
521-
from distutils.core import setup, Extension
522-
setup(name="custom", version="1.0",
523-
ext_modules=[
524-
Extension("custom", ["custom.c"]),
525-
Extension("custom2", ["custom2.c"]),
526-
])
517+
from setuptools import Extension, setup
518+
setup(ext_modules=[
519+
Extension("custom", ["custom.c"]),
520+
Extension("custom2", ["custom2.c"]),
521+
])
522+
523+
and then we re-install so that we can ``import custom2``:
524+
525+
.. code-block:: shell-session
527526
527+
$ python -m pip install .
528528
529529
Providing finer control over data attributes
530530
============================================
@@ -535,7 +535,7 @@ version of our module, the instance variables :attr:`!first` and :attr:`!last`
535535
could be set to non-string values or even deleted. We want to make sure that
536536
these attributes always contain strings.
537537

538-
.. literalinclude:: ../includes/custom3.c
538+
.. literalinclude:: ../includes/newtypes/custom3.c
539539

540540

541541
To provide greater control, over the :attr:`!first` and :attr:`!last` attributes,
@@ -682,7 +682,7 @@ To allow a :class:`!Custom` instance participating in a reference cycle to
682682
be properly detected and collected by the cyclic GC, our :class:`!Custom` type
683683
needs to fill two additional slots and to enable a flag that enables these slots:
684684

685-
.. literalinclude:: ../includes/custom4.c
685+
.. literalinclude:: ../includes/newtypes/custom4.c
686686

687687

688688
First, the traversal method lets the cyclic GC know about subobjects that could
@@ -806,7 +806,7 @@ increases an internal counter:
806806
>>> print(s.increment())
807807
2
808808
809-
.. literalinclude:: ../includes/sublist.c
809+
.. literalinclude:: ../includes/newtypes/sublist.c
810810

811811

812812
As you can see, the source code closely resembles the :class:`!Custom` examples in
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)