This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: sum() works with bytes objects
Type: behavior Stage: needs patch
Components: Interpreter Core Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: mark.dickinson, pitrou, python-dev, rhettinger
Priority: normal Keywords:

Created on 2011-07-29 12:45 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg141363 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-07-29 12:45
... while it apparently shouldn't:

>>> sum([b'', b''], b'')
b''
>>> sum([b'', b''], bytearray())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: sum() can't sum bytes [use b''.join(seq) instead]


In 2.7, the situation is the reverse:

>>> sum([b'', b''], b'')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: sum() can't sum strings [use ''.join(seq) instead]
>>> sum([b'', b''], bytearray())
bytearray(b'')
msg141408 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-07-29 19:24
New changeset 7368d0e9b33e by Benjamin Peterson in branch 'default':
bytes should be verboten in sum() (fixes #12654)
http://hg.python.org/cpython/rev/7368d0e9b33e
History
Date User Action Args
2022-04-11 14:57:20adminsetgithub: 56863
2011-07-29 21:08:35benjamin.petersonsetstatus: open -> closed
resolution: fixed
2011-07-29 19:24:42python-devsetnosy: + python-dev
messages: + msg141408
2011-07-29 12:45:31pitroucreate