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.

Title: bytearray documentation confuses string for unicode objects
Type: behavior Stage: resolved
Components: Documentation Versions: Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: docs@python, mjpieters, python-dev, terry.reedy
Priority: normal Keywords:

Created on 2014-10-07 17:34 by mjpieters, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg228771 - (view) Author: Martijn Pieters (mjpieters) * Date: 2014-10-07 17:34
The Python 2 version of the bytearray() documentation appears to be copied directly from its Python 3 counterpart and states that when passing in a string an encoding is required:

* If it is a string, you must also give the encoding (and optionally, errors) parameters; bytearray() then converts the string to bytes using str.encode().


This obviously doesn't apply to Python 2 str() objects, but would only apply to unicode() objects.

Can this be corrected? The current wording is confusing new users (see
msg229017 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-10-10 17:03
New changeset 0c75819f1d86 by Terry Jan Reedy in branch '2.7':
Issue #22575: Revise bytearray entry for 2.7.
msg229018 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-10-10 17:06
I changed the line to 
* If it is unicode, you must also give the encoding (and optionally, errors) parameters; bytearray() then converts the unicode to bytes using unicode.encode().

Thank you for the report, and for your work answering questions on SO
Date User Action Args
2022-04-11 14:58:08adminsetgithub: 66765
2014-10-10 17:06:42terry.reedysetstatus: open -> closed

type: behavior
assignee: docs@python -> terry.reedy

nosy: + terry.reedy
messages: + msg229018
resolution: fixed
stage: resolved
2014-10-10 17:03:18python-devsetnosy: + python-dev
messages: + msg229017
2014-10-07 17:34:20mjpieterscreate