Commits

Brian Kearns  committed 722d0a4

some more behavioral fixes for datetime

  • Participants
  • Parent commits b628683

Comments (0)

Files changed (2)

File lib_pypy/datetime.py

         else:
             if isinstance(value, (int, long)):
                 return value
-    raise TypeError('integer argument expected')
+    raise TypeError('an integer is required')
 
 def _check_date_fields(year, month, day):
     year = _check_int_field(year)
 
         year, month, day (required, base 1)
         """
-        if isinstance(year, str):
+        if isinstance(year, str) and len(year) == 4:
             # Pickle support
             self = object.__new__(cls)
             self.__setstate(year)
 
     def __new__(cls, year, month=None, day=None, hour=0, minute=0, second=0,
                 microsecond=0, tzinfo=None):
-        if isinstance(year, str):
+        if isinstance(year, str) and len(year) == 10:
             # Pickle support
             self = date.__new__(cls, year[:4])
             self.__setstate(year, month)

File pypy/module/test_lib_pypy/test_datetime.py

     a = datetime.timedelta()
     raises(AttributeError, 'a.abc = 1')
 
+def test_unpickle():
+    e = raises(TypeError, datetime.date, '123')
+    assert e.value.args[0] == 'an integer is required'
+    e = raises(TypeError, datetime.time, '123')
+    assert e.value.args[0] == 'an integer is required'
+    e = raises(TypeError, datetime.datetime, '123')
+    assert e.value.args[0] == 'an integer is required'
+
 def test_strptime():
     import time, sys
     if sys.version_info < (2, 6):