[issue41740] string concatenation via `sum`

2020-09-07 Thread Marco Paolini


Marco Paolini  added the comment:

also worth noting, the start argument is type checked instead. Maybe we could 
apply the same checks to the items of the iterable?

python3 -c "print(sum(('a', 'b', 'c'), start='d'))"
Traceback (most recent call last):
  File "", line 1, in 
TypeError: sum() can't sum strings [use ''.join(seq) instead]


see 
https://github.com/python/cpython/blob/c96d00e88ead8f99bb6aa1357928ac4545d9287c/Python/bltinmodule.c#L2310

--

___
Python tracker 

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



[issue41740] string concatenation via `sum`

2020-09-07 Thread Marco Paolini


Marco Paolini  added the comment:

This happens because the default value for the start argument is zero , hence 
the first operation is `0 + 'a'`

--
nosy: +mpaolini

___
Python tracker 

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



[issue41740] string concatenation via `sum`

2020-09-07 Thread Phillip M. Feldman


New submission from Phillip M. Feldman :

I'm not sure whether this is a bug or a feature request, but it seems as though 
the following should produce the same result:

In [1]: 'a' + 'b' + 'c'
Out[1]: 'abc'

In [2]: sum(('a', 'b', 'c'))
TypeError Traceback (most recent call last)
in
> 1 sum(('a', 'b', 'c'))

TypeError: unsupported operand type(s) for +: 'int' and 'str'

The error message is confusing (there is no integer).

--
components: Interpreter Core
messages: 376526
nosy: phillip.m.feld...@gmail.com
priority: normal
severity: normal
status: open
title: string concatenation via `sum`
type: behavior
versions: Python 3.8

___
Python tracker 

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