Commits

Matthew Schinckel committed 8cde0b7

Throw an exception if an empty string is passed to parse.

Comments (0)

Files changed (2)

             return value
         if isinstance(value, int):
             return datetime.timedelta(seconds=value)
-        if value == "":
-            return None
         return parse(value)
     
     def get_prep_value(self, value):
     ...
     TypeError: '2 ss' is not a valid time interval
     >>> parse("")
-    datetime.timedelta(0)
+    Traceback (most recent call last):
+    ...
+    TypeError: '' is not a valid time interval
     
     """
+    if string == "":
+        raise TypeError("'%s' is not a valid time interval" % string)
     # This is the format we get from sometimes Postgres, and from serialization
     d = re.match(r'((?P<days>\d+) days?,? )?(?P<hours>\d+):'
                  r'(?P<minutes>\d+)(:(?P<seconds>\d+))?',