New issue 2127: datetime.timedelta.__mul__ causes OverflowError for random
multiplier
https://bitbucket.org/pypy/pypy/issues/2127/datetimetimedelta__mul__-causes
Victor Sergienko:
timezone.timedelta(weeks=52) * random.random() causes OverflowError:
File "/Users/vic/Documents/pypy3/lib-python/3/datetime.py", line 534, in
__mul__
return self * a / b
File "/Users/vic/Documents/pypy3/lib-python/3/datetime.py", line 531, in
__mul__
self._microseconds * other)
File "/Users/vic/Documents/pypy3/lib-python/3/datetime.py", line 430, in
__new__
raise OverflowError("timedelta # of days is too large: %d" % d)
OverflowError: timedelta # of days is too large: 2492507137960926996
Probably it's because of this implementation:
def __mul__(self, other):
...
if isinstance(other, float):
a, b = other.as_integer_ratio()
return self * a / b
where `as_integer_ratio()` returns a very big nominator and denominator - which
is reasonable for random numbers.
_______________________________________________
pypy-issue mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-issue