[Python-checkins] bpo-37372: Fix error unpickling datetime.time objects from Python 2 with seconds>=24. (GH-14307)

Miss Islington (bot) webhook-mailer at python.org
Thu Aug 29 03:56:10 EDT 2019


https://github.com/python/cpython/commit/d1d42bf4a404f092fe90fe8984481c507a64ef0a
commit: d1d42bf4a404f092fe90fe8984481c507a64ef0a
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-08-29T00:56:04-07:00
summary:

bpo-37372: Fix error unpickling datetime.time objects from Python 2 with seconds>=24. (GH-14307)

(cherry picked from commit 122376df550b71dd3bec0513c7483cc1714212fa)

Co-authored-by: Justin Blanchard <UncombedCoconut at gmail.com>

files:
A Misc/NEWS.d/next/Library/2019-06-22-12-30-00.bpo-37372.kIKqZ6.rst
M Lib/test/datetimetester.py
M Misc/ACKS
M Modules/_datetimemodule.c

diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index 58004870a00f..b440e5ab5fa6 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -3324,16 +3324,25 @@ def test_pickling_subclass_time(self):
 
     def test_compat_unpickle(self):
         tests = [
-            b"cdatetime\ntime\n(S'\\x14;\\x10\\x00\\x10\\x00'\ntR.",
-            b'cdatetime\ntime\n(U\x06\x14;\x10\x00\x10\x00tR.',
-            b'\x80\x02cdatetime\ntime\nU\x06\x14;\x10\x00\x10\x00\x85R.',
+            (b"cdatetime\ntime\n(S'\\x14;\\x10\\x00\\x10\\x00'\ntR.",
+             (20, 59, 16, 64**2)),
+            (b'cdatetime\ntime\n(U\x06\x14;\x10\x00\x10\x00tR.',
+             (20, 59, 16, 64**2)),
+            (b'\x80\x02cdatetime\ntime\nU\x06\x14;\x10\x00\x10\x00\x85R.',
+             (20, 59, 16, 64**2)),
+            (b"cdatetime\ntime\n(S'\\x14;\\x19\\x00\\x10\\x00'\ntR.",
+             (20, 59, 25, 64**2)),
+            (b'cdatetime\ntime\n(U\x06\x14;\x19\x00\x10\x00tR.',
+             (20, 59, 25, 64**2)),
+            (b'\x80\x02cdatetime\ntime\nU\x06\x14;\x19\x00\x10\x00\x85R.',
+             (20, 59, 25, 64**2)),
         ]
-        args = 20, 59, 16, 64**2
-        expected = self.theclass(*args)
-        for data in tests:
-            for loads in pickle_loads:
-                derived = loads(data, encoding='latin1')
-                self.assertEqual(derived, expected)
+        for i, (data, args) in enumerate(tests):
+            with self.subTest(i=i):
+                expected = self.theclass(*args)
+                for loads in pickle_loads:
+                    derived = loads(data, encoding='latin1')
+                    self.assertEqual(derived, expected)
 
     def test_bool(self):
         # time is always True.
diff --git a/Misc/ACKS b/Misc/ACKS
index 5a8494f1a827..24e327a5f86e 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -162,6 +162,7 @@ Roy Bixler
 Daniel Black
 Jonathan Black
 Renaud Blanch
+Justin Blanchard
 Mike Bland
 Martin Bless
 Pablo Bleyer
diff --git a/Misc/NEWS.d/next/Library/2019-06-22-12-30-00.bpo-37372.kIKqZ6.rst b/Misc/NEWS.d/next/Library/2019-06-22-12-30-00.bpo-37372.kIKqZ6.rst
new file mode 100644
index 000000000000..b958d8fed40a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-06-22-12-30-00.bpo-37372.kIKqZ6.rst
@@ -0,0 +1,2 @@
+Fix error unpickling datetime.time objects from Python 2 with seconds>=24.
+Patch by Justin Blanchard.
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index e6abfc2cb223..d3c3f0905386 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -4081,7 +4081,7 @@ time_new(PyTypeObject *type, PyObject *args, PyObject *kw)
                 return NULL;
             }
             if (PyUnicode_GET_LENGTH(state) == _PyDateTime_TIME_DATASIZE &&
-                (0x7F & PyUnicode_READ_CHAR(state, 2)) < 24)
+                (0x7F & PyUnicode_READ_CHAR(state, 0)) < 24)
             {
                 state = PyUnicode_AsLatin1String(state);
                 if (state == NULL) {



More information about the Python-checkins mailing list