[Python-checkins] GH-84976: Move Lib/datetime.py to Lib/_pydatetime

Yhg1s webhook-mailer at python.org
Wed May 3 05:10:17 EDT 2023


https://github.com/python/cpython/commit/65c4a2b326086875ecbedf032204d1ff24ba74d7
commit: 65c4a2b326086875ecbedf032204d1ff24ba74d7
branch: main
author: Paul Ganssle <git at m.ganssle.io>
committer: Yhg1s <thomas at python.org>
date: 2023-05-03T03:09:45-06:00
summary:

GH-84976: Move Lib/datetime.py to Lib/_pydatetime

This breaks the tests, but we are keeping it as a separate commit so
that the move operation and editing of the moved files are separate, for
a cleaner history.

files:
A Lib/_pydatetime.py
D Lib/datetime.py
M Lib/test/datetimetester.py
M Lib/test/test_datetime.py
M Python/stdlib_module_names.h

diff --git a/Lib/datetime.py b/Lib/_pydatetime.py
similarity index 100%
rename from Lib/datetime.py
rename to Lib/_pydatetime.py
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index c5eb6e7f1643..fb07d2a5ad9b 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -39,6 +39,10 @@
 
 # Needed by test_datetime
 import _strptime
+try:
+    import _pydatetime
+except ImportError:
+    pass
 #
 
 pickle_loads = {pickle.loads, pickle._loads}
@@ -92,7 +96,7 @@ def test_divide_and_round(self):
         if '_Fast' in self.__class__.__name__:
             self.skipTest('Only run for Pure Python implementation')
 
-        dar = datetime_module._divide_and_round
+        dar = _pydatetime._divide_and_round
 
         self.assertEqual(dar(-10, -3), 3)
         self.assertEqual(dar(5, -2), -2)
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py
index 7f9094fa7bd4..3859733a4fe6 100644
--- a/Lib/test/test_datetime.py
+++ b/Lib/test/test_datetime.py
@@ -8,10 +8,12 @@
 
 def load_tests(loader, tests, pattern):
     try:
-        pure_tests = import_fresh_module(TESTS, fresh=['datetime', '_strptime'],
-                                        blocked=['_datetime'])
-        fast_tests = import_fresh_module(TESTS, fresh=['datetime',
-                                                    '_datetime', '_strptime'])
+        pure_tests = import_fresh_module(TESTS,
+                                         fresh=['datetime', '_pydatetime', '_strptime'],
+                                         blocked=['_datetime'])
+        fast_tests = import_fresh_module(TESTS,
+                                         fresh=['datetime', '_strptime'],
+                                         blocked=['_pydatetime'])
     finally:
         # XXX: import_fresh_module() is supposed to leave sys.module cache untouched,
         # XXX: but it does not, so we have to cleanup ourselves.
@@ -42,6 +44,8 @@ def setUpClass(cls_, module=module):
                 cls_._save_sys_modules = sys.modules.copy()
                 sys.modules[TESTS] = module
                 sys.modules['datetime'] = module.datetime_module
+                if hasattr(module, '_pydatetime'):
+                    sys.modules['_pydatetime'] = module._pydatetime
                 sys.modules['_strptime'] = module._strptime
             @classmethod
             def tearDownClass(cls_):
diff --git a/Python/stdlib_module_names.h b/Python/stdlib_module_names.h
index 27f42e5202e5..ed4a0ac2dd32 100644
--- a/Python/stdlib_module_names.h
+++ b/Python/stdlib_module_names.h
@@ -56,6 +56,7 @@ static const char* _Py_stdlib_module_names[] = {
 "_posixshmem",
 "_posixsubprocess",
 "_py_abc",
+"_pydatetime",
 "_pydecimal",
 "_pyio",
 "_pylong",



More information about the Python-checkins mailing list