-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
gh-141004: Document missing PyDateTime* 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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ZeroIntensity
merged 6 commits into
python:main
from
ZeroIntensity:document-datetime-capsule-name
Nov 20, 2025
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
50116ee
Document missing PyDateTime* APIs.
ZeroIntensity 35347c7
Fix typo.
ZeroIntensity 737ecf9
Apply suggestion from @StanFromIreland
ZeroIntensity 5d43c50
Apply suggestion from @StanFromIreland
ZeroIntensity aa9d630
Fix semicolon shenanigans.
ZeroIntensity a9be066
Update Doc/c-api/datetime.rst
ZeroIntensity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,11 +8,43 @@ 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 */ } | ||||||
StanFromIreland marked this conversation as resolved.
Show resolved
Hide resolved
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
|
|
||||||
| .. 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. | ||||||
|
|
@@ -325,3 +357,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`. | ||||||
|
|
||||||
ZeroIntensity marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| 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. | ||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.