Commits

Brian Kearns committed 722d0a4

some more behavioral fixes for datetime

Comments (0)

Files changed (2)

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)

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):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.