Skip to content

Commit 7a27c7b

Browse files
miss-islingtonZeroIntensityStanFromIrelandvstinner
authored
[3.13] gh-141004: Document missing PyDateTime* APIs (GH-141543) (GH-141792)
gh-141004: Document missing `PyDateTime*` APIs (GH-141543) (cherry picked from commit 4273616) Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent e90d895 commit 7a27c7b

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

Doc/c-api/datetime.rst

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,42 @@ DateTime Objects
88
Various date and time objects are supplied by the :mod:`datetime` module.
99
Before using any of these functions, the header file :file:`datetime.h` must be
1010
included in your source (note that this is not included by :file:`Python.h`),
11-
and the macro :c:macro:`!PyDateTime_IMPORT` must be invoked, usually as part of
11+
and the macro :c:macro:`PyDateTime_IMPORT` must be invoked, usually as part of
1212
the module initialisation function. The macro puts a pointer to a C structure
13-
into a static variable, :c:data:`!PyDateTimeAPI`, that is used by the following
13+
into a static variable, :c:data:`PyDateTimeAPI`, that is used by the following
1414
macros.
1515

16+
.. c:macro:: PyDateTime_IMPORT()
17+
18+
Import the datetime C API.
19+
20+
On success, populate the :c:var:`PyDateTimeAPI` pointer.
21+
On failure, set :c:var:`PyDateTimeAPI` to ``NULL`` and set an exception.
22+
The caller must check if an error occurred via :c:func:`PyErr_Occurred`:
23+
24+
.. code-block::
25+
26+
PyDateTime_IMPORT;
27+
if (PyErr_Occurred()) { /* cleanup */ }
28+
29+
.. warning::
30+
31+
This is not compatible with subinterpreters.
32+
33+
.. c:type:: PyDateTime_CAPI
34+
35+
Structure containing the fields for the datetime C API.
36+
37+
The fields of this structure are private and subject to change.
38+
39+
Do not use this directly; prefer ``PyDateTime_*`` APIs instead.
40+
41+
.. c:var:: PyDateTime_CAPI *PyDateTimeAPI
42+
43+
Dynamically allocated object containing the datetime C API.
44+
45+
This variable is only available once :c:macro:`PyDateTime_IMPORT` succeeds.
46+
1647
.. c:type:: PyDateTime_Date
1748
1849
This subtype of :c:type:`PyObject` represents a Python date object.
@@ -325,3 +356,16 @@ Macros for the convenience of modules implementing the DB API:
325356
326357
Create and return a new :class:`datetime.date` object given an argument
327358
tuple suitable for passing to :meth:`datetime.date.fromtimestamp`.
359+
360+
361+
Internal data
362+
-------------
363+
364+
The following symbols are exposed by the C API but should be considered
365+
internal-only.
366+
367+
.. c:macro:: PyDateTime_CAPSULE_NAME
368+
369+
Name of the datetime capsule to pass to :c:func:`PyCapsule_Import`.
370+
371+
Internal usage only. Use :c:macro:`PyDateTime_IMPORT` instead.

0 commit comments

Comments
 (0)