Skip to content

Commit faf4957

Browse files
bpo-42528: Improve the docs of most Py*_Check{,Exact} API calls (GH-23602) (GH-24139)
I think that none of these API calls can fail, but only few of them are documented as such. Add the sentence "This function always succeeds" (which is the same already used e.g. by PyNumber_Check) to all of them. (cherry picked from commit 315fc52) Co-authored-by: Antonio Cuni <[email protected]> Co-authored-by: Antonio Cuni <[email protected]>
1 parent a3ca674 commit faf4957

26 files changed

+74
-52
lines changed

Doc/c-api/bool.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ are available, however.
1313

1414
.. c:function:: int PyBool_Check(PyObject *o)
1515
16-
Return true if *o* is of type :c:data:`PyBool_Type`.
16+
Return true if *o* is of type :c:data:`PyBool_Type`. This function always
17+
succeeds.
1718
1819
1920
.. c:var:: PyObject* Py_False

Doc/c-api/bytearray.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ Type check macros
2525
.. c:function:: int PyByteArray_Check(PyObject *o)
2626
2727
Return true if the object *o* is a bytearray object or an instance of a
28-
subtype of the bytearray type.
28+
subtype of the bytearray type. This function always succeeds.
2929
3030
3131
.. c:function:: int PyByteArray_CheckExact(PyObject *o)
3232
3333
Return true if the object *o* is a bytearray object, but not an instance of a
34-
subtype of the bytearray type.
34+
subtype of the bytearray type. This function always succeeds.
3535
3636
3737
Direct API functions

Doc/c-api/bytes.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ called with a non-bytes parameter.
2525
.. c:function:: int PyBytes_Check(PyObject *o)
2626
2727
Return true if the object *o* is a bytes object or an instance of a subtype
28-
of the bytes type.
28+
of the bytes type. This function always succeeds.
2929
3030
3131
.. c:function:: int PyBytes_CheckExact(PyObject *o)
3232
3333
Return true if the object *o* is a bytes object, but not an instance of a
34-
subtype of the bytes type.
34+
subtype of the bytes type. This function always succeeds.
3535
3636
3737
.. c:function:: PyObject* PyBytes_FromString(const char *v)

Doc/c-api/capsule.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ Refer to :ref:`using-capsules` for more information on using these objects.
3434

3535
.. c:function:: int PyCapsule_CheckExact(PyObject *p)
3636
37-
Return true if its argument is a :c:type:`PyCapsule`.
37+
Return true if its argument is a :c:type:`PyCapsule`. This function always
38+
succeeds.
3839
3940
4041
.. c:function:: PyObject* PyCapsule_New(void *pointer, const char *name, PyCapsule_Destructor destructor)

Doc/c-api/cell.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Cell objects are not likely to be useful elsewhere.
2727

2828
.. c:function:: int PyCell_Check(ob)
2929
30-
Return true if *ob* is a cell object; *ob* must not be ``NULL``.
30+
Return true if *ob* is a cell object; *ob* must not be ``NULL``. This
31+
function always succeeds.
3132

3233

3334
.. c:function:: PyObject* PyCell_New(PyObject *ob)

Doc/c-api/code.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bound into a function.
2727

2828
.. c:function:: int PyCode_Check(PyObject *co)
2929
30-
Return true if *co* is a :class:`code` object.
30+
Return true if *co* is a :class:`code` object. This function always succeeds.
3131
3232
.. c:function:: int PyCode_GetNumFree(PyCodeObject *co)
3333

Doc/c-api/complex.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ Complex Numbers as Python Objects
9494
.. c:function:: int PyComplex_Check(PyObject *p)
9595
9696
Return true if its argument is a :c:type:`PyComplexObject` or a subtype of
97-
:c:type:`PyComplexObject`.
97+
:c:type:`PyComplexObject`. This function always succeeds.
9898
9999
100100
.. c:function:: int PyComplex_CheckExact(PyObject *p)
101101
102102
Return true if its argument is a :c:type:`PyComplexObject`, but not a subtype of
103-
:c:type:`PyComplexObject`.
103+
:c:type:`PyComplexObject`. This function always succeeds.
104104
105105
106106
.. c:function:: PyObject* PyComplex_FromCComplex(Py_complex v)

Doc/c-api/coro.rst

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ return.
2424
.. c:function:: int PyCoro_CheckExact(PyObject *ob)
2525
2626
Return true if *ob*'s type is :c:type:`PyCoro_Type`; *ob* must not be ``NULL``.
27+
This function always succeeds.
2728
2829
2930
.. c:function:: PyObject* PyCoro_New(PyFrameObject *frame, PyObject *name, PyObject *qualname)

Doc/c-api/datetime.rst

+15-10
Original file line numberDiff line numberDiff line change
@@ -28,61 +28,66 @@ Type-check macros:
2828
.. c:function:: int PyDate_Check(PyObject *ob)
2929
3030
Return true if *ob* is of type :c:data:`PyDateTime_DateType` or a subtype of
31-
:c:data:`PyDateTime_DateType`. *ob* must not be ``NULL``.
31+
:c:data:`PyDateTime_DateType`. *ob* must not be ``NULL``. This function always
32+
succeeds.
3233
3334
3435
.. c:function:: int PyDate_CheckExact(PyObject *ob)
3536
3637
Return true if *ob* is of type :c:data:`PyDateTime_DateType`. *ob* must not be
37-
``NULL``.
38+
``NULL``. This function always succeeds.
3839
3940
4041
.. c:function:: int PyDateTime_Check(PyObject *ob)
4142
4243
Return true if *ob* is of type :c:data:`PyDateTime_DateTimeType` or a subtype of
43-
:c:data:`PyDateTime_DateTimeType`. *ob* must not be ``NULL``.
44+
:c:data:`PyDateTime_DateTimeType`. *ob* must not be ``NULL``. This function always
45+
succeeds.
4446
4547
4648
.. c:function:: int PyDateTime_CheckExact(PyObject *ob)
4749
4850
Return true if *ob* is of type :c:data:`PyDateTime_DateTimeType`. *ob* must not
49-
be ``NULL``.
51+
be ``NULL``. This function always succeeds.
5052
5153
5254
.. c:function:: int PyTime_Check(PyObject *ob)
5355
5456
Return true if *ob* is of type :c:data:`PyDateTime_TimeType` or a subtype of
55-
:c:data:`PyDateTime_TimeType`. *ob* must not be ``NULL``.
57+
:c:data:`PyDateTime_TimeType`. *ob* must not be ``NULL``. This function always
58+
succeeds.
5659
5760
5861
.. c:function:: int PyTime_CheckExact(PyObject *ob)
5962
6063
Return true if *ob* is of type :c:data:`PyDateTime_TimeType`. *ob* must not be
61-
``NULL``.
64+
``NULL``. This function always succeeds.
6265
6366
6467
.. c:function:: int PyDelta_Check(PyObject *ob)
6568
6669
Return true if *ob* is of type :c:data:`PyDateTime_DeltaType` or a subtype of
67-
:c:data:`PyDateTime_DeltaType`. *ob* must not be ``NULL``.
70+
:c:data:`PyDateTime_DeltaType`. *ob* must not be ``NULL``. This function always
71+
succeeds.
6872
6973
7074
.. c:function:: int PyDelta_CheckExact(PyObject *ob)
7175
7276
Return true if *ob* is of type :c:data:`PyDateTime_DeltaType`. *ob* must not be
73-
``NULL``.
77+
``NULL``. This function always succeeds.
7478
7579
7680
.. c:function:: int PyTZInfo_Check(PyObject *ob)
7781
7882
Return true if *ob* is of type :c:data:`PyDateTime_TZInfoType` or a subtype of
79-
:c:data:`PyDateTime_TZInfoType`. *ob* must not be ``NULL``.
83+
:c:data:`PyDateTime_TZInfoType`. *ob* must not be ``NULL``. This function always
84+
succeeds.
8085
8186
8287
.. c:function:: int PyTZInfo_CheckExact(PyObject *ob)
8388
8489
Return true if *ob* is of type :c:data:`PyDateTime_TZInfoType`. *ob* must not be
85-
``NULL``.
90+
``NULL``. This function always succeeds.
8691
8792
8893
Macros to create objects:

Doc/c-api/dict.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ Dictionary Objects
2222
.. c:function:: int PyDict_Check(PyObject *p)
2323
2424
Return true if *p* is a dict object or an instance of a subtype of the dict
25-
type.
25+
type. This function always succeeds.
2626
2727
2828
.. c:function:: int PyDict_CheckExact(PyObject *p)
2929
3030
Return true if *p* is a dict object, but not an instance of a subtype of
31-
the dict type.
31+
the dict type. This function always succeeds.
3232
3333
3434
.. c:function:: PyObject* PyDict_New()

Doc/c-api/float.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ Floating Point Objects
2222
.. c:function:: int PyFloat_Check(PyObject *p)
2323
2424
Return true if its argument is a :c:type:`PyFloatObject` or a subtype of
25-
:c:type:`PyFloatObject`.
25+
:c:type:`PyFloatObject`. This function always succeeds.
2626
2727
2828
.. c:function:: int PyFloat_CheckExact(PyObject *p)
2929
3030
Return true if its argument is a :c:type:`PyFloatObject`, but not a subtype of
31-
:c:type:`PyFloatObject`.
31+
:c:type:`PyFloatObject`. This function always succeeds.
3232
3333
3434
.. c:function:: PyObject* PyFloat_FromString(PyObject *str)

Doc/c-api/function.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ There are a few functions specific to Python functions.
2626
.. c:function:: int PyFunction_Check(PyObject *o)
2727
2828
Return true if *o* is a function object (has type :c:data:`PyFunction_Type`).
29-
The parameter must not be ``NULL``.
29+
The parameter must not be ``NULL``. This function always succeeds.
3030
3131
3232
.. c:function:: PyObject* PyFunction_New(PyObject *code, PyObject *globals)

Doc/c-api/gen.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`.
2222

2323
.. c:function:: int PyGen_Check(PyObject *ob)
2424
25-
Return true if *ob* is a generator object; *ob* must not be ``NULL``.
25+
Return true if *ob* is a generator object; *ob* must not be ``NULL``. This
26+
function always succeeds.
2627
2728
2829
.. c:function:: int PyGen_CheckExact(PyObject *ob)
2930
30-
Return true if *ob*'s type is :c:type:`PyGen_Type`; *ob* must not be ``NULL``.
31+
Return true if *ob*'s type is :c:type:`PyGen_Type`; *ob* must not be
32+
``NULL``. This function always succeeds.
3133
3234
3335
.. c:function:: PyObject* PyGen_New(PyFrameObject *frame)

Doc/c-api/iter.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ There are two functions specifically for working with iterators.
99

1010
.. c:function:: int PyIter_Check(PyObject *o)
1111
12-
Return true if the object *o* supports the iterator protocol.
12+
Return true if the object *o* supports the iterator protocol. This
13+
function always succeeds.
1314
1415
1516
.. c:function:: PyObject* PyIter_Next(PyObject *o)

Doc/c-api/iterator.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ sentinel value is returned.
2121

2222
.. c:function:: int PySeqIter_Check(op)
2323
24-
Return true if the type of *op* is :c:data:`PySeqIter_Type`.
24+
Return true if the type of *op* is :c:data:`PySeqIter_Type`. This function
25+
always succeeds.
2526
2627
2728
.. c:function:: PyObject* PySeqIter_New(PyObject *seq)
@@ -39,7 +40,8 @@ sentinel value is returned.
3940
4041
.. c:function:: int PyCallIter_Check(op)
4142
42-
Return true if the type of *op* is :c:data:`PyCallIter_Type`.
43+
Return true if the type of *op* is :c:data:`PyCallIter_Type`. This
44+
function always succeeds.
4345
4446
4547
.. c:function:: PyObject* PyCallIter_New(PyObject *callable, PyObject *sentinel)

Doc/c-api/list.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ List Objects
2222
.. c:function:: int PyList_Check(PyObject *p)
2323
2424
Return true if *p* is a list object or an instance of a subtype of the list
25-
type.
25+
type. This function always succeeds.
2626
2727
2828
.. c:function:: int PyList_CheckExact(PyObject *p)
2929
3030
Return true if *p* is a list object, but not an instance of a subtype of
31-
the list type.
31+
the list type. This function always succeeds.
3232
3333
3434
.. c:function:: PyObject* PyList_New(Py_ssize_t len)

Doc/c-api/long.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
2727
.. c:function:: int PyLong_Check(PyObject *p)
2828
2929
Return true if its argument is a :c:type:`PyLongObject` or a subtype of
30-
:c:type:`PyLongObject`.
30+
:c:type:`PyLongObject`. This function always succeeds.
3131
3232
3333
.. c:function:: int PyLong_CheckExact(PyObject *p)
3434
3535
Return true if its argument is a :c:type:`PyLongObject`, but not a subtype of
36-
:c:type:`PyLongObject`.
36+
:c:type:`PyLongObject`. This function always succeeds.
3737
3838
3939
.. c:function:: PyObject* PyLong_FromLong(long v)

Doc/c-api/memoryview.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ any other object.
4545
.. c:function:: int PyMemoryView_Check(PyObject *obj)
4646
4747
Return true if the object *obj* is a memoryview object. It is not
48-
currently allowed to create subclasses of :class:`memoryview`.
48+
currently allowed to create subclasses of :class:`memoryview`. This
49+
function always succeeds.
4950
5051
5152
.. c:function:: Py_buffer *PyMemoryView_GET_BUFFER(PyObject *mview)

Doc/c-api/method.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ to bind a :c:data:`PyCFunction` to a class object. It replaces the former call
2222
2323
Return true if *o* is an instance method object (has type
2424
:c:data:`PyInstanceMethod_Type`). The parameter must not be ``NULL``.
25+
This function always succeeds.
2526
2627
2728
.. c:function:: PyObject* PyInstanceMethod_New(PyObject *func)
@@ -64,7 +65,7 @@ no longer available.
6465
.. c:function:: int PyMethod_Check(PyObject *o)
6566
6667
Return true if *o* is a method object (has type :c:data:`PyMethod_Type`). The
67-
parameter must not be ``NULL``.
68+
parameter must not be ``NULL``. This function always succeeds.
6869
6970
7071
.. c:function:: PyObject* PyMethod_New(PyObject *func, PyObject *self)

Doc/c-api/module.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ Module Objects
1919
.. c:function:: int PyModule_Check(PyObject *p)
2020
2121
Return true if *p* is a module object, or a subtype of a module object.
22+
This function always succeeds.
2223
2324
2425
.. c:function:: int PyModule_CheckExact(PyObject *p)
2526
2627
Return true if *p* is a module object, but not a subtype of
27-
:c:data:`PyModule_Type`.
28+
:c:data:`PyModule_Type`. This function always succeeds.
2829
2930
3031
.. c:function:: PyObject* PyModule_NewObject(PyObject *name)

Doc/c-api/set.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,29 @@ the constructor functions work with any iterable Python object.
5353
.. c:function:: int PySet_Check(PyObject *p)
5454
5555
Return true if *p* is a :class:`set` object or an instance of a subtype.
56+
This function always succeeds.
5657
5758
.. c:function:: int PyFrozenSet_Check(PyObject *p)
5859
5960
Return true if *p* is a :class:`frozenset` object or an instance of a
60-
subtype.
61+
subtype. This function always succeeds.
6162
6263
.. c:function:: int PyAnySet_Check(PyObject *p)
6364
6465
Return true if *p* is a :class:`set` object, a :class:`frozenset` object, or an
65-
instance of a subtype.
66+
instance of a subtype. This function always succeeds.
6667
6768
6869
.. c:function:: int PyAnySet_CheckExact(PyObject *p)
6970
7071
Return true if *p* is a :class:`set` object or a :class:`frozenset` object but
71-
not an instance of a subtype.
72+
not an instance of a subtype. This function always succeeds.
7273
7374
7475
.. c:function:: int PyFrozenSet_CheckExact(PyObject *p)
7576
7677
Return true if *p* is a :class:`frozenset` object but not an instance of a
77-
subtype.
78+
subtype. This function always succeeds.
7879
7980
8081
.. c:function:: PyObject* PySet_New(PyObject *iterable)

Doc/c-api/slice.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Slice Objects
1414

1515
.. c:function:: int PySlice_Check(PyObject *ob)
1616
17-
Return true if *ob* is a slice object; *ob* must not be ``NULL``.
17+
Return true if *ob* is a slice object; *ob* must not be ``NULL``. This
18+
function always succeeds.
1819
1920
2021
.. c:function:: PyObject* PySlice_New(PyObject *start, PyObject *stop, PyObject *step)

Doc/c-api/tuple.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ Tuple Objects
2121

2222
.. c:function:: int PyTuple_Check(PyObject *p)
2323
24-
Return true if *p* is a tuple object or an instance of a subtype of the tuple
25-
type.
24+
Return true if *p* is a tuple object or an instance of a subtype of the
25+
tuple type. This function always succeeds.
2626
2727
2828
.. c:function:: int PyTuple_CheckExact(PyObject *p)
2929
3030
Return true if *p* is a tuple object, but not an instance of a subtype of the
31-
tuple type.
31+
tuple type. This function always succeeds.
3232
3333
3434
.. c:function:: PyObject* PyTuple_New(Py_ssize_t len)

0 commit comments

Comments
 (0)