[Python-Dev] Why is PyDateTimeAPI not initialized by datetime module import?

Skip Montanaro skip.montanaro at gmail.com
Thu Jan 26 11:00:38 EST 2017


I just got burned (wasted a good day or so) by the fact that PyDateTimeAPI
wasn't initialized. The datetime.rst doc states (emphasis mine):

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 the module initialisation function*.

I thought that surely the datetime module itself would initialize that
stuff. Why not? Is it so terribly expensive that the C API requires this
rather weird hack? The code's been their for ages, so there must have been
a good reason at one time. Is that reason still valid today? (I haven't
programmed at the C API level for a good long while, or I'm sure I'd have
encountered this before.)

Thx,

Skip
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20170126/8f58ff1e/attachment-0001.html>


More information about the Python-Dev mailing list