Invalid relativedelta object when float `second` is given

Bug #1188507 reported by Petr Viktorin
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
dateutil
New
Undecided
Unassigned

Bug Description

relativedelta should not allow float arguments for the `second` (and other) keyword arguments; this results in invalid objects that raise errors when used.

>>> from dateutil.relativedelta import relativedelta
>>> import datetime
>>> relativedelta(second=0.4)
relativedelta(second=0.4)
>>> relativedelta(second=0.3, microsecond=78)
relativedelta(second=0.3, microsecond=78)
>>> datetime.datetime.now() + relativedelta(second=4.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/dateutil/relativedelta.py", line 271, in __radd__
    ret = (other.replace(**repl)
TypeError: integer argument expected, got float

Either __init__ should catch the error early or the value should be normalized and converted to int.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.