[Python-checkins] bpo-41966: Fix pickling pure datetime.time subclasses (GH-22731) (GH-22748)

Miss Skeleton (bot) webhook-mailer at python.org
Sun Oct 18 11:33:32 EDT 2020


https://github.com/python/cpython/commit/1040299e9283609f3de0f6e32a0d43458fe7f4f6
commit: 1040299e9283609f3de0f6e32a0d43458fe7f4f6
branch: 3.8
author: Miss Skeleton (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020年10月18日T18:33:28+03:00
summary:
bpo-41966: Fix pickling pure datetime.time subclasses (GH-22731) (GH-22748)
(cherry picked from commit c304c9a7efa8751b5bc7526fa95cd5f30aac2b92)
Co-authored-by: scaramallion <scaramallion at users.noreply.github.com>
files:
A Misc/NEWS.d/next/Library/2020-10-17-07-52-53.bpo-41966.gwEQRZ.rst
M Lib/datetime.py
M Lib/test/datetimetester.py
M Misc/ACKS
diff --git a/Lib/datetime.py b/Lib/datetime.py
index 96d112c197069..9777e88df6ca4 100644
--- a/Lib/datetime.py
+++ b/Lib/datetime.py
@@ -1545,7 +1545,7 @@ def __setstate(self, string, tzinfo):
 self._tzinfo = tzinfo
 
 def __reduce_ex__(self, protocol):
- return (time, self._getstate(protocol))
+ return (self.__class__, self._getstate(protocol))
 
 def __reduce__(self):
 return self.__reduce_ex__(2)
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index d1a3c2ff9abc2..bb94f8fb3b195 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -1750,6 +1750,7 @@ def test_pickling_subclass_date(self):
 green = pickler.dumps(orig, proto)
 derived = unpickler.loads(green)
 self.assertEqual(orig, derived)
+ self.assertTrue(isinstance(derived, SubclassDate))
 
 def test_backdoor_resistance(self):
 # For fast unpickling, the constructor accepts a pickle byte string.
@@ -2277,6 +2278,7 @@ def test_pickling_subclass_datetime(self):
 green = pickler.dumps(orig, proto)
 derived = unpickler.loads(green)
 self.assertEqual(orig, derived)
+ self.assertTrue(isinstance(derived, SubclassDatetime))
 
 def test_compat_unpickle(self):
 tests = [
@@ -3326,6 +3328,7 @@ def test_pickling_subclass_time(self):
 green = pickler.dumps(orig, proto)
 derived = unpickler.loads(green)
 self.assertEqual(orig, derived)
+ self.assertTrue(isinstance(derived, SubclassTime))
 
 def test_compat_unpickle(self):
 tests = [
diff --git a/Misc/ACKS b/Misc/ACKS
index 8d355da8fde05..5584d5d54a0b2 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -759,6 +759,7 @@ Meador Inge
 Peter Ingebretson
 Tony Ingraldi
 John Interrante
+Dean Inwood
 Bob Ippolito
 Roger Irwin
 Atsuo Ishimoto
diff --git a/Misc/NEWS.d/next/Library/2020-10-17-07-52-53.bpo-41966.gwEQRZ.rst b/Misc/NEWS.d/next/Library/2020-10-17-07-52-53.bpo-41966.gwEQRZ.rst
new file mode 100644
index 0000000000000..0e7fad40077be
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-10-17-07-52-53.bpo-41966.gwEQRZ.rst
@@ -0,0 +1,2 @@
+Fix pickling pure Python :class:`datetime.time` subclasses. Patch by Dean
+Inwood.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /