[New-bugs-announce] [issue1083] Confusing error message when dividing timedelta using /

Skip Montanaro report at bugs.python.org
Sat Sep 1 21:19:34 CEST 2007


New submission from Skip Montanaro:

I discovered the hard way today that this won't work:

>>> import datetime
>>> d = datetime.timedelta(1)
>>> d / 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for /: 'datetime.timedelta' and 'int'

The error message is misleading, because in fact timedelta
objects *do* support division by ints, just not with the
/ operator:

>>> d // 2
datetime.timedelta(0, 43200)

Is there some way the error message can be improved,
perhaps by identifying the denominator as effectively
a float?

----------
components: Interpreter Core
messages: 55566
nosy: skip.montanaro
severity: normal
status: open
title: Confusing error message when dividing timedelta using /
type: behavior

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1083>
__________________________________


More information about the New-bugs-announce mailing list