From: scaramallion Date: Sun, 18 Oct 2020 14:49:48 +0000 (+1100) Subject: bpo-41966: Fix pickling pure datetime.time subclasses (GH-22731) X-Git-Tag: v3.10.0a2~172 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c304c9a7efa8751b5bc7526fa95cd5f30aac2b92;p=thirdparty%2FPython%2Fcpython.git bpo-41966: Fix pickling pure datetime.time subclasses (GH-22731) --- diff --git a/Lib/datetime.py b/Lib/datetime.py index ea86bcb8b238..b896b94b0fe0 100644 --- a/Lib/datetime.py +++ b/Lib/datetime.py @@ -1548,7 +1548,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) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 8b61c26f9e5c..775d3151ae29 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -1781,6 +1781,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. @@ -2308,6 +2309,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 = [ @@ -3357,6 +3359,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 = [ diff --git a/Misc/ACKS b/Misc/ACKS index 7f4a9bcbc0f8..d81d0a255145 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -787,6 +787,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 000000000000..0e7fad40077b --- /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.