[Python-checkins] python/nondist/sandbox/datetime datetime.py,1.158,1.159 test_datetime.py,1.113,1.114
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Fri, 07 Feb 2003 13:40:40 -0800
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv9646
Modified Files:
datetime.py test_datetime.py
Log Message:
Tres discovered a weird bug when a datetime is pickled, caused by the
shadowing of __year, __month, __day and the use of proxies.
Here's a quick fix and a quick unit test. I don't quite understand
why this wasn't caught by the pickling unit tests.
Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.158
retrieving revision 1.159
diff -C2 -d -r1.158 -r1.159
*** datetime.py 7 Feb 2003 20:47:58 -0000 1.158
--- datetime.py 7 Feb 2003 21:40:34 -0000 1.159
***************
*** 1360,1364 ****
if isinstance(year, str):
# Pickle support
! self = date.__new__(cls, 1, 1, 1)
self.__setstate((year, month))
return self
--- 1360,1364 ----
if isinstance(year, str):
# Pickle support
! self = date.__new__(cls, year[:4])
self.__setstate((year, month))
return self
Index: test_datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/test_datetime.py,v
retrieving revision 1.113
retrieving revision 1.114
diff -C2 -d -r1.113 -r1.114
*** test_datetime.py 7 Feb 2003 20:47:59 -0000 1.113
--- test_datetime.py 7 Feb 2003 21:40:36 -0000 1.114
***************
*** 1224,1227 ****
--- 1224,1235 ----
self.assertEqual(orig, derived)
+ def test_more_pickling(self):
+ a = self.theclass(2003, 2, 7, 16, 48, 37, 444116)
+ s = pickle.dumps(a)
+ b = pickle.loads(s)
+ self.assertEqual(b.year, 2003)
+ self.assertEqual(b.month, 2)
+ self.assertEqual(b.day, 7)
+
def test_more_compare(self):
# The test_compare() inherited from TestDate covers the error cases.