Skip to content

Commit 6eff004

Browse files
[3.9] More minor fixes to C API docs (GH-31525) (GH-32259)
* wording fixes in type.rst * grammar and punctuation in sys.rst * set: grammar fixes * structures: capitalization fix * grammar fixes for sequence * objects: point to Py_TYPE instead of direct object access * numbers: add more explicit Python equivalences * method: add missing period * memory: grammar fix * mapping: grammar fixes * long: grammar fix * iter: fix grammar for PyAIter_Check * init: grammar fix. (cherry picked from commit 897bc6f) Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent 74138ac commit 6eff004

File tree

11 files changed

+26
-25
lines changed

11 files changed

+26
-25
lines changed

Doc/c-api/init.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,7 @@ is not possible due to its implementation being opaque at build time.
16881688
argument is `NULL`.
16891689
16901690
.. note::
1691-
A freed key becomes a dangling pointer, you should reset the key to
1691+
A freed key becomes a dangling pointer. You should reset the key to
16921692
`NULL`.
16931693
16941694

Doc/c-api/long.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
4141
Return a new :c:type:`PyLongObject` object from *v*, or ``NULL`` on failure.
4242
4343
The current implementation keeps an array of integer objects for all integers
44-
between ``-5`` and ``256``, when you create an int in that range you actually
44+
between ``-5`` and ``256``. When you create an int in that range you actually
4545
just get back a reference to the existing object.
4646
4747

Doc/c-api/mapping.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ See also :c:func:`PyObject_GetItem`, :c:func:`PyObject_SetItem` and
1111

1212
.. c:function:: int PyMapping_Check(PyObject *o)
1313
14-
Return ``1`` if the object provides mapping protocol or supports slicing,
14+
Return ``1`` if the object provides the mapping protocol or supports slicing,
1515
and ``0`` otherwise. Note that it returns ``1`` for Python classes with
16-
a :meth:`__getitem__` method since in general case it is impossible to
17-
determine what type of keys it supports. This function always succeeds.
16+
a :meth:`__getitem__` method, since in general it is impossible to
17+
determine what type of keys the class supports. This function always succeeds.
1818
1919
2020
.. c:function:: Py_ssize_t PyMapping_Size(PyObject *o)

Doc/c-api/method.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ to bind a :c:data:`PyCFunction` to a class object. It replaces the former call
2727
2828
.. c:function:: PyObject* PyInstanceMethod_New(PyObject *func)
2929
30-
Return a new instance method object, with *func* being any callable object
30+
Return a new instance method object, with *func* being any callable object.
3131
*func* is the function that will be called when the instance method is
3232
called.
3333

Doc/c-api/number.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Number Protocol
4444
.. c:function:: PyObject* PyNumber_FloorDivide(PyObject *o1, PyObject *o2)
4545
4646
Return the floor of *o1* divided by *o2*, or ``NULL`` on failure. This is
47-
equivalent to the "classic" division of integers.
47+
the equivalent of the Python expression ``o1 // o2``.
4848
4949
5050
.. c:function:: PyObject* PyNumber_TrueDivide(PyObject *o1, PyObject *o2)
@@ -53,7 +53,7 @@ Number Protocol
5353
*o2*, or ``NULL`` on failure. The return value is "approximate" because binary
5454
floating point numbers are approximate; it is not possible to represent all real
5555
numbers in base two. This function can return a floating point value when
56-
passed two integers.
56+
passed two integers. This is the equivalent of the Python expression ``o1 / o2``.
5757
5858
5959
.. c:function:: PyObject* PyNumber_Remainder(PyObject *o1, PyObject *o2)
@@ -180,6 +180,7 @@ Number Protocol
180180
floating point numbers are approximate; it is not possible to represent all real
181181
numbers in base two. This function can return a floating point value when
182182
passed two integers. The operation is done *in-place* when *o1* supports it.
183+
This is the equivalent of the Python statement ``o1 /= o2``.
183184
184185
185186
.. c:function:: PyObject* PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2)
@@ -281,6 +282,6 @@ Number Protocol
281282
282283
.. c:function:: int PyIndex_Check(PyObject *o)
283284
284-
Returns ``1`` if *o* is an index integer (has the nb_index slot of the
285-
tp_as_number structure filled in), and ``0`` otherwise.
285+
Returns ``1`` if *o* is an index integer (has the ``nb_index`` slot of the
286+
``tp_as_number`` structure filled in), and ``0`` otherwise.
286287
This function always succeeds.

Doc/c-api/object.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Object Protocol
9393
return ``0`` on success. This is the equivalent of the Python statement
9494
``o.attr_name = v``.
9595
96-
If *v* is ``NULL``, the attribute is deleted, however this feature is
96+
If *v* is ``NULL``, the attribute is deleted, but this feature is
9797
deprecated in favour of using :c:func:`PyObject_DelAttrString`.
9898
9999
@@ -291,7 +291,7 @@ Object Protocol
291291
of object *o*. On failure, raises :exc:`SystemError` and returns ``NULL``. This
292292
is equivalent to the Python expression ``type(o)``. This function increments the
293293
reference count of the return value. There's really no reason to use this
294-
function instead of the common expression ``o->ob_type``, which returns a
294+
function instead of the :c:func:`Py_TYPE()` function, which returns a
295295
pointer of type :c:type:`PyTypeObject*`, except when the incremented reference
296296
count is needed.
297297

Doc/c-api/sequence.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ Sequence Protocol
88

99
.. c:function:: int PySequence_Check(PyObject *o)
1010
11-
Return ``1`` if the object provides sequence protocol, and ``0`` otherwise.
11+
Return ``1`` if the object provides the sequence protocol, and ``0`` otherwise.
1212
Note that it returns ``1`` for Python classes with a :meth:`__getitem__`
13-
method unless they are :class:`dict` subclasses since in general case it
14-
is impossible to determine what the type of keys it supports. This
13+
method, unless they are :class:`dict` subclasses, since in general it
14+
is impossible to determine what type of keys the class supports. This
1515
function always succeeds.
1616
1717
@@ -69,7 +69,7 @@ Sequence Protocol
6969
is the equivalent of the Python statement ``o[i] = v``. This function *does
7070
not* steal a reference to *v*.
7171
72-
If *v* is ``NULL``, the element is deleted, however this feature is
72+
If *v* is ``NULL``, the element is deleted, but this feature is
7373
deprecated in favour of using :c:func:`PySequence_DelItem`.
7474
7575
@@ -147,7 +147,7 @@ Sequence Protocol
147147
148148
Returns the length of *o*, assuming that *o* was returned by
149149
:c:func:`PySequence_Fast` and that *o* is not ``NULL``. The size can also be
150-
gotten by calling :c:func:`PySequence_Size` on *o*, but
150+
retrieved by calling :c:func:`PySequence_Size` on *o*, but
151151
:c:func:`PySequence_Fast_GET_SIZE` is faster because it can assume *o* is a
152152
list or tuple.
153153

Doc/c-api/set.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Set Objects
1313
object: frozenset
1414

1515
This section details the public API for :class:`set` and :class:`frozenset`
16-
objects. Any functionality not listed below is best accessed using the either
16+
objects. Any functionality not listed below is best accessed using either
1717
the abstract object protocol (including :c:func:`PyObject_CallMethod`,
1818
:c:func:`PyObject_RichCompareBool`, :c:func:`PyObject_Hash`,
1919
:c:func:`PyObject_Repr`, :c:func:`PyObject_IsTrue`, :c:func:`PyObject_Print`, and
@@ -31,7 +31,7 @@ the abstract object protocol (including :c:func:`PyObject_CallMethod`,
3131
in that it is a fixed size for small sets (much like tuple storage) and will
3232
point to a separate, variable sized block of memory for medium and large sized
3333
sets (much like list storage). None of the fields of this structure should be
34-
considered public and are subject to change. All access should be done through
34+
considered public and all are subject to change. All access should be done through
3535
the documented API rather than by manipulating the values in the structure.
3636

3737

@@ -125,7 +125,7 @@ or :class:`frozenset` or instances of their subtypes.
125125
.. c:function:: int PySet_Add(PyObject *set, PyObject *key)
126126
127127
Add *key* to a :class:`set` instance. Also works with :class:`frozenset`
128-
instances (like :c:func:`PyTuple_SetItem` it can be used to fill-in the values
128+
instances (like :c:func:`PyTuple_SetItem` it can be used to fill in the values
129129
of brand new frozensets before they are exposed to other code). Return ``0`` on
130130
success or ``-1`` on failure. Raise a :exc:`TypeError` if the *key* is
131131
unhashable. Raise a :exc:`MemoryError` if there is no room to grow. Raise a

Doc/c-api/structures.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ Accessing attributes of extension types
461461
+=============+==================+===================================+
462462
| name | const char \* | attribute name |
463463
+-------------+------------------+-----------------------------------+
464-
| get | getter | C Function to get the attribute |
464+
| get | getter | C function to get the attribute |
465465
+-------------+------------------+-----------------------------------+
466466
| set | setter | optional C function to set or |
467467
| | | delete the attribute, if omitted |

Doc/c-api/sys.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ Operating System Utilities
185185
186186
Return a pointer to a newly allocated byte string, use :c:func:`PyMem_Free`
187187
to free the memory. Return ``NULL`` on encoding error or memory allocation
188-
error
188+
error.
189189
190190
If error_pos is not ``NULL``, ``*error_pos`` is set to ``(size_t)-1`` on
191191
success, or set to the index of the invalid character on encoding error.
@@ -205,7 +205,7 @@ Operating System Utilities
205205
206206
.. versionchanged:: 3.8
207207
The function now uses the UTF-8 encoding on Windows if
208-
:c:data:`Py_LegacyWindowsFSEncodingFlag` is zero;
208+
:c:data:`Py_LegacyWindowsFSEncodingFlag` is zero.
209209
210210
211211
.. _systemfunctions:
@@ -336,7 +336,7 @@ accessible to C code. They all work with the current interpreter thread's
336336
.. c:function:: int PySys_AddAuditHook(Py_AuditHookFunction hook, void *userData)
337337
338338
Append the callable *hook* to the list of active auditing hooks.
339-
Return zero for success
339+
Return zero on success
340340
and non-zero on failure. If the runtime has been initialized, also set an
341341
error on failure. Hooks added through this API are called for all
342342
interpreters created by the runtime.

Doc/c-api/type.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ The following functions and structs are used to create
266266
267267
.. versionchanged:: 3.9
268268
269-
Slots in :c:type:`PyBufferProcs` in may be set in the unlimited API.
269+
Slots in :c:type:`PyBufferProcs` may be set in the unlimited API.
270270
271271
.. c:member:: void *PyType_Slot.pfunc
272272

0 commit comments

Comments
 (0)