]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41966: Fix pickling pure datetime.time subclasses (GH-22731) (GH-22748)
authorMiss Skeleton (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 18 Oct 2020 15:33:28 +0000 (08:33 -0700)
committerGitHub <noreply@github.com>
Sun, 18 Oct 2020 15:33:28 +0000 (18:33 +0300)
(cherry picked from commit c304c9a7efa8751b5bc7526fa95cd5f30aac2b92)

Co-authored-by: scaramallion <scaramallion@users.noreply.github.com>
Lib/datetime.py
Lib/test/datetimetester.py
Misc/ACKS
Misc/NEWS.d/next/Library/2020-10-17-07-52-53.bpo-41966.gwEQRZ.rst [new file with mode: 0644]

index 96d112c197069e1961190d200627a6b8f80d04c6..9777e88df6ca4f9dd20ff48a33090d4b31630f5e 100644 (file)
@@ -1545,7 +1545,7 @@ class time:
         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)
index d1a3c2ff9abc21766c701b8e179a82ff219044a8..bb94f8fb3b1954883a5890d6b15a657d7737ecf6 100644 (file)
@@ -1750,6 +1750,7 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase):
             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 @@ class TestDateTime(TestDate):
             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 @@ class TestTime(HarmlessMixedComparison, unittest.TestCase):
             green = pickler.dumps(orig, proto)
             derived = unpickler.loads(green)
             self.assertEqual(orig, derived)
+            self.assertTrue(isinstance(derived, SubclassTime))
 
     def test_compat_unpickle(self):
         tests = [
index 8d355da8fde055aef1d0239139926d7e77fb1485..5584d5d54a0b250c87b2d3f95b039f5c8467d2ac 100644 (file)
--- 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 (file)
index 0000000..0e7fad4
--- /dev/null
@@ -0,0 +1,2 @@
+Fix pickling pure Python :class:`datetime.time` subclasses. Patch by Dean
+Inwood.