Skip to content

Commit d1d42bf

Browse files
bpo-37372: Fix error unpickling datetime.time objects from Python 2 with seconds>=24. (GH-14307)
(cherry picked from commit 122376d) Co-authored-by: Justin Blanchard <UncombedCoconut@gmail.com>
1 parent 097eae5 commit d1d42bf

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

Lib/test/datetimetester.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3324,16 +3324,25 @@ def test_pickling_subclass_time(self):
33243324

33253325
def test_compat_unpickle(self):
33263326
tests = [
3327-
b"cdatetime\ntime\n(S'\\x14;\\x10\\x00\\x10\\x00'\ntR.",
3328-
b'cdatetime\ntime\n(U\x06\x14;\x10\x00\x10\x00tR.',
3329-
b'\x80\x02cdatetime\ntime\nU\x06\x14;\x10\x00\x10\x00\x85R.',
3327+
(b"cdatetime\ntime\n(S'\\x14;\\x10\\x00\\x10\\x00'\ntR.",
3328+
(20, 59, 16, 64**2)),
3329+
(b'cdatetime\ntime\n(U\x06\x14;\x10\x00\x10\x00tR.',
3330+
(20, 59, 16, 64**2)),
3331+
(b'\x80\x02cdatetime\ntime\nU\x06\x14;\x10\x00\x10\x00\x85R.',
3332+
(20, 59, 16, 64**2)),
3333+
(b"cdatetime\ntime\n(S'\\x14;\\x19\\x00\\x10\\x00'\ntR.",
3334+
(20, 59, 25, 64**2)),
3335+
(b'cdatetime\ntime\n(U\x06\x14;\x19\x00\x10\x00tR.',
3336+
(20, 59, 25, 64**2)),
3337+
(b'\x80\x02cdatetime\ntime\nU\x06\x14;\x19\x00\x10\x00\x85R.',
3338+
(20, 59, 25, 64**2)),
33303339
]
3331-
args = 20, 59, 16, 64**2
3332-
expected = self.theclass(*args)
3333-
for data in tests:
3334-
for loads in pickle_loads:
3335-
derived = loads(data, encoding='latin1')
3336-
self.assertEqual(derived, expected)
3340+
for i, (data, args) in enumerate(tests):
3341+
with self.subTest(i=i):
3342+
expected = self.theclass(*args)
3343+
for loads in pickle_loads:
3344+
derived = loads(data, encoding='latin1')
3345+
self.assertEqual(derived, expected)
33373346

33383347
def test_bool(self):
33393348
# time is always True.

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ Roy Bixler
162162
Daniel Black
163163
Jonathan Black
164164
Renaud Blanch
165+
Justin Blanchard
165166
Mike Bland
166167
Martin Bless
167168
Pablo Bleyer
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix error unpickling datetime.time objects from Python 2 with seconds>=24.
2+
Patch by Justin Blanchard.

Modules/_datetimemodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4081,7 +4081,7 @@ time_new(PyTypeObject *type, PyObject *args, PyObject *kw)
40814081
return NULL;
40824082
}
40834083
if (PyUnicode_GET_LENGTH(state) == _PyDateTime_TIME_DATASIZE &&
4084-
(0x7F & PyUnicode_READ_CHAR(state, 2)) < 24)
4084+
(0x7F & PyUnicode_READ_CHAR(state, 0)) < 24)
40854085
{
40864086
state = PyUnicode_AsLatin1String(state);
40874087
if (state == NULL) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy