Skip to content

Commit cf86e36

Browse files
committed
Issue #7989: Added pure python implementation of the datetime module.
1 parent c2721b0 commit cf86e36

File tree

9 files changed

+5813
-3670
lines changed

9 files changed

+5813
-3670
lines changed

‎Lib/datetime.py‎

Lines changed: 2087 additions & 0 deletions
Large diffs are not rendered by default.

‎Lib/test/datetimetester.py‎

Lines changed: 3674 additions & 0 deletions
Large diffs are not rendered by default.

‎Lib/test/test_datetime.py‎

Lines changed: 36 additions & 3662 deletions
Large diffs are not rendered by default.

‎Misc/NEWS‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,14 @@ C-API
473473
Library
474474
-------
475475

476+
- Issue #7989: Added pure python implementation of the `datetime`
477+
module. The C module is renamed to `_datetime` and if available,
478+
overrides all classes defined in datetime with fast C impementation.
479+
Python implementation is based on the original python prototype for
480+
the datetime module by Tim Peters with minor modifications by the
481+
PyPy project. The test suite now tests `datetime` module with and
482+
without `_datetime` acceleration using the same test cases.
483+
476484
- Issue #7895: platform.mac_ver() no longer crashes after calling os.fork()
477485

478486
- Issue #9323: Fixed a bug in trace.py that resulted in loosing the

‎Modules/Setup.dist‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ _symtable symtablemodule.c
170170
#atexit atexitmodule.c # Register functions to be run at interpreter-shutdown
171171
#_elementtree -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI _elementtree.c # elementtree accelerator
172172
#_pickle _pickle.c # pickle accelerator
173-
#datetime datetimemodule.c # date/time type
173+
#_datetime _datetimemodule.c # datetime accelerator
174174
#_bisect _bisectmodule.c # Bisection algorithms
175175
#_heapq _heapqmodule.c # Heap queue algorithm
176176

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* final result fits in a C int (this can be an issue on 64-bit boxes).
2626
*/
2727
#if SIZEOF_INT < 4
28-
# error "datetime.c requires that C int have at least 32 bits"
28+
# error "_datetime.c requires that C int have at least 32 bits"
2929
#endif
3030

3131
#define MINYEAR 1
@@ -5086,7 +5086,7 @@ static PyDateTime_CAPI CAPI = {
50865086

50875087
static struct PyModuleDef datetimemodule = {
50885088
PyModuleDef_HEAD_INIT,
5089-
"datetime",
5089+
"_datetime",
50905090
"Fast implementation of the datetime type.",
50915091
-1,
50925092
module_methods,
@@ -5097,7 +5097,7 @@ static struct PyModuleDef datetimemodule = {
50975097
};
50985098

50995099
PyMODINIT_FUNC
5100-
PyInit_datetime(void)
5100+
PyInit__datetime(void)
51015101
{
51025102
PyObject *m; /* a module object */
51035103
PyObject *d; /* its dict */

‎PC/config.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extern PyObject* PyInit__sre(void);
4343
extern PyObject* PyInit_parser(void);
4444
extern PyObject* PyInit_winreg(void);
4545
extern PyObject* PyInit__struct(void);
46-
extern PyObject* PyInit_datetime(void);
46+
extern PyObject* PyInit__datetime(void);
4747
extern PyObject* PyInit__functools(void);
4848
extern PyObject* PyInit__json(void);
4949
extern PyObject* PyInit_zlib(void);
@@ -116,7 +116,7 @@ struct _inittab _PyImport_Inittab[] = {
116116
{"parser", PyInit_parser},
117117
{"winreg", PyInit_winreg},
118118
{"_struct", PyInit__struct},
119-
{"datetime", PyInit_datetime},
119+
{"_datetime", PyInit__datetime},
120120
{"_functools", PyInit__functools},
121121
{"_json", PyInit__json},
122122

‎PCbuild/pythoncore.vcproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@
10681068
>
10691069
</File>
10701070
<File
1071-
RelativePath="..\Modules\datetimemodule.c"
1071+
RelativePath="..\Modules\_datetimemodule.c"
10721072
>
10731073
</File>
10741074
<File

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def detect_modules(self):
452452
# time operations and variables
453453
exts.append( Extension('time', ['timemodule.c', '_time.c'],
454454
libraries=math_libs) )
455-
exts.append( Extension('datetime', ['datetimemodule.c', '_time.c'],
455+
exts.append( Extension('_datetime', ['_datetimemodule.c', '_time.c'],
456456
libraries=math_libs) )
457457
# fast iterator tools implemented in C
458458
exts.append( Extension("itertools", ["itertoolsmodule.c"]) )

0 commit comments

Comments
 (0)