8000 [3.8] bpo-41966: Fix pickling pure datetime.time subclasses (GH-22731) by miss-islington · Pull Request #22748 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ Meador Inge
Peter Ingebretson
Tony Ingraldi
John Interrante
Dean Inwood
Bob Ippolito
Roger Irwin
Atsuo Ishimoto
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix pickling pure Python :class:`datetime.time` subclasses. Patch by Dean
Inwood.
0