Skip to content

Commit 5492f84

Browse files
authored
[3.12] gh-121615: Improve module.rst C-API docs with better error descriptions (GH-121616) (#121619)
(cherry picked from commit e6264b4)
1 parent 847c803 commit 5492f84

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Doc/c-api/module.rst

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Module Objects
4343
to ``None``); the caller is responsible for providing a :attr:`__file__`
4444
attribute.
4545
46+
Return ``NULL`` with an exception set on error.
47+
4648
.. versionadded:: 3.3
4749
4850
.. versionchanged:: 3.4
@@ -265,6 +267,8 @@ of the following two module creation functions:
265267
API version *module_api_version*. If that version does not match the version
266268
of the running interpreter, a :exc:`RuntimeWarning` is emitted.
267269
270+
Return ``NULL`` with an exception set on error.
271+
268272
.. note::
269273
270274
Most uses of this function should be using :c:func:`PyModule_Create`
@@ -436,6 +440,8 @@ objects dynamically. Note that both ``PyModule_FromDefAndSpec`` and
436440
If that version does not match the version of the running interpreter,
437441
a :exc:`RuntimeWarning` is emitted.
438442
443+
Return ``NULL`` with an exception set on error.
444+
439445
.. note::
440446
441447
Most uses of this function should be using :c:func:`PyModule_FromDefAndSpec`
@@ -579,23 +585,24 @@ state:
579585
.. c:function:: int PyModule_AddIntConstant(PyObject *module, const char *name, long value)
580586
581587
Add an integer constant to *module* as *name*. This convenience function can be
582-
used from the module's initialization function. Return ``-1`` on error, ``0`` on
583-
success.
588+
used from the module's initialization function.
589+
Return ``-1`` with an exception set on error, ``0`` on success.
584590
585591
586592
.. c:function:: int PyModule_AddStringConstant(PyObject *module, const char *name, const char *value)
587593
588594
Add a string constant to *module* as *name*. This convenience function can be
589595
used from the module's initialization function. The string *value* must be
590-
``NULL``-terminated. Return ``-1`` on error, ``0`` on success.
596+
``NULL``-terminated.
597+
Return ``-1`` with an exception set on error, ``0`` on success.
591598
592599
593600
.. c:macro:: PyModule_AddIntMacro(module, macro)
594601
595602
Add an int constant to *module*. The name and the value are taken from
596603
*macro*. For example ``PyModule_AddIntMacro(module, AF_INET)`` adds the int
597604
constant *AF_INET* with the value of *AF_INET* to *module*.
598-
Return ``-1`` on error, ``0`` on success.
605+
Return ``-1`` with an exception set on error, ``0`` on success.
599606
600607
601608
.. c:macro:: PyModule_AddStringMacro(module, macro)
@@ -608,7 +615,7 @@ state:
608615
The type object is finalized by calling internally :c:func:`PyType_Ready`.
609616
The name of the type object is taken from the last component of
610617
:c:member:`~PyTypeObject.tp_name` after dot.
611-
Return ``-1`` on error, ``0`` on success.
618+
Return ``-1`` with an exception set on error, ``0`` on success.
612619
613620
.. versionadded:: 3.9
614621
@@ -647,14 +654,14 @@ since multiple such modules can be created from a single definition.
647654
648655
The caller must hold the GIL.
649656
650-
Return 0 on success or -1 on failure.
657+
Return ``-1`` with an exception set on error, ``0`` on success.
651658
652659
.. versionadded:: 3.3
653660
654661
.. c:function:: int PyState_RemoveModule(PyModuleDef *def)
655662
656663
Removes the module object created from *def* from the interpreter state.
657-
Return 0 on success or -1 on failure.
664+
Return ``-1`` with an exception set on error, ``0`` on success.
658665
659666
The caller must hold the GIL.
660667

0 commit comments

Comments
 (0)