[issue11576] timedelta subtraction glitch on big timedelta values
Alexander Belopolsky
report at bugs.python.org
Tue Apr 5 19:39:45 CEST 2011
Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:
> What happens is the second value is negated (__neg__)
> which causes it to become less than timedelta.min and
> that is causing OverflowError.
Yes, and running the test case without C acceleration makes this obvious:
>>> import sys
>>> sys.modules['_datetime'] = None
>>> from datetime import *
>>> timedelta(999999999, 86399, 999999) - timedelta(999999999, 86399, 999998)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "Lib/datetime.py", line 488, in __sub__
return self + -other
File "Lib/datetime.py", line 501, in __neg__
-self._microseconds)
File "Lib/datetime.py", line 426, in __new__
raise OverflowError("timedelta # of days is too large: %d" % d)
OverflowError: timedelta # of days is too large: -1000000000
Attached patch fixes the issue. I would like to think some more about C int overflow before committing.
----------
assignee: -> belopolsky
keywords: +patch
nosy: +mark.dickinson
stage: -> patch review
Added file: http://bugs.python.org/file21543/issue11576.diff
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11576>
_______________________________________
More information about the Python-bugs-list
mailing list