[issue25549] call sum on list of timedelta throws TypeError

2021-07-26 Thread sedrubal


sedrubal  added the comment:

What is the reason for this start parameter? Why will sum not just use the 
first entry of the input sequence?

I think at least a error message that points programmers into the right 
direction was very helpful.

--
nosy: +sedrubal

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25549] call sum on list of timedelta throws TypeError

2015-11-04 Thread R. David Murray

R. David Murray added the comment:

I don't think this warrants a special error message.  If you get it, it is 
obvious you weren't yourself adding an int to a timedelta, so the next logical 
course of action should be to look at the docs for sum.

--
nosy: +r.david.murray
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25549] call sum on list of timedelta throws TypeError

2015-11-03 Thread Emanuel Barry

Emanuel Barry added the comment:

`sum` has an optional `start` parameter, which defaults to 0, and is used as 
the first item to add. Since timedeltas and ints are not interoperable, that 
means you have to explicitly tell sum what to use.

The following code works:

>>> e=[datetime.timedelta(3), datetime.timedelta(5)]
>>> sum(e, datetime.timedelta(0))
datetime.timedelta(8)

This is not a bug, but maybe this could use a more descriptive error message? I 
don't know.

--
nosy: +ebarry

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25549] call sum on list of timedelta throws TypeError

2015-11-03 Thread Kevin Jing Qiu

New submission from Kevin Jing Qiu:

Calling sum() on a list of timedelta objects results in TypeError: unsupported 
operand type(s) for +: 'int' and 'datetime.timedelta'

Here's a script that illustrates this behaviour:  (also attached)

import datetime

x = [datetime.timedelta(1), datetime.timedelta(2)]
print(x[0] + x[1])  # datetime.timedelta(3)
print(sum(x))  # TypeError: unsupported operand type(s) for +: 'int' and 
'datetime.timedelta'


The bug is present in all version of Python 2 and Python 3

--
components: Library (Lib)
files: demo.py
messages: 254038
nosy: kevinjqiu
priority: normal
severity: normal
status: open
title: call sum on list of timedelta throws TypeError
type: behavior
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6
Added file: http://bugs.python.org/file40938/demo.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com