Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-141004: Document missingPyDateTime* APIs.#141543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some comments aren't visible on the classic Files Changed page.

48 changes: 46 additions & 2 deletionsDoc/c-api/datetime.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,11 +8,42 @@ DateTime Objects
Various date and time objects are supplied by the :mod:`datetime` module.
Before using any of these functions, the header file :file:`datetime.h` must be
included in your source (note that this is not included by :file:`Python.h`),
and the macro :c:macro:`!PyDateTime_IMPORT` must be invoked, usually as part of
and the macro :c:macro:`PyDateTime_IMPORT` must be invoked, usually as part of
the module initialisation function. The macro puts a pointer to a C structure
into a static variable, :c:data:`!PyDateTimeAPI`, that is used by the following
into a static variable, :c:data:`PyDateTimeAPI`, that is used by the following
macros.

.. c:macro:: PyDateTime_IMPORT()

Import the datetime C API.

On success, populate the :c:var:`PyDateTimeAPI` pointer.
On failure, set :c:var:`PyDateTimeAPI` to ``NULL`` and set an exception.
The caller must check if an error occurred via :c:func:`PyErr_Occurred`:

.. code-block::

PyDateTime_IMPORT;
if (PyErr_Occurred()) { /* cleanup */ }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
if (PyErr_Occurred()) { /*cleanup */ }
if (PyErr_Occurred()) { /*error */ }

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I like the current comment, we do similar for the curses C API:https://docs.python.org/3/c-api/curses.html

vstinner reacted with thumbs up emoji

.. warning::

This is not compatible with subinterpreters.

.. c:type:: PyDateTime_CAPI

Structure containing the fields for the datetime C API.

The fields of this structure are private and subject to change.

Do not use this directly; prefer ``PyDateTime_*`` APIs instead.

.. c:var:: PyDateTime_CAPI *PyDateTimeAPI

Dynamically allocated object containing the datetime C API.

This variable is only available once :c:macro:`PyDateTime_IMPORT` succeeds.

.. c:type:: PyDateTime_Date

This subtype of :c:type:`PyObject` represents a Python date object.
Expand DownExpand Up@@ -325,3 +356,16 @@ Macros for the convenience of modules implementing the DB API:

Create and return a new :class:`datetime.date` object given an argument
tuple suitable for passing to :meth:`datetime.date.fromtimestamp`.


Internal data
-------------

The following symbols are exposed by the C API but should be considered
internal-only.

.. c:macro:: PyDateTime_CAPSULE_NAME

Name of the datetime capsule to pass to :c:func:`PyCapsule_Import`.

Internal usage only. Use :c:macro:`PyDateTime_IMPORT` instead.
Loading

[8]ページ先頭

©2009-2026 Movatter.jp