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.

Author martin.panter
Recipients eric.smith, ezio.melotti, mahmoud, martin.panter, vstinner
Date 2015-04-22.00:15:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1429661754.13.0.377768741128.issue24019@psf.upfronthosting.co.za>
In-reply-to
Content
I don’t think changes to Python 2 are considered here, unless they are bug fixes, and this does not sound like a bug fix.

For Python 3, it sounds like you are proposing that str() accept encoding arguments even when not decoding from bytes. It sounds like this would mask the error if you called str(buffer, "ascii"), and the buffer happened to be an integer or a list, etc, by accident. Also, this woul

It seems str() is designed to have two separate modes:

1. str(object) is basically equivalent to format(object), with a warning if “object” happens to be a byte string or array

2. str(object, encoding, ...) is normally equivalent to object.decode(encoding, ...), or if that is not supported, codecs.decode(object, encoding, ...)

Your proposal sounds like it would make it easier to confuse these two modes. What should str(b"123", encoding=None) do? Why should the behaviour of str(file, encoding) vary depending on whether an ordinary file object or a memory-mapped file is passed?

IMO in a perfect Python 4 world, str() would only have a single personality (perhaps always returning an empty string, or a more strict conversion). Making a formatted string representations of arbitrary objects would be left to the format() and repr() functions, and decoding bytes to text would be left to the existing decode() methods and functions, or maybe a separate str.from_bytes() constructor, mirroring int.from_bytes().
History
Date User Action Args
2015-04-22 00:15:54martin.pantersetrecipients: + martin.panter, vstinner, eric.smith, ezio.melotti, mahmoud
2015-04-22 00:15:54martin.pantersetmessageid: <1429661754.13.0.377768741128.issue24019@psf.upfronthosting.co.za>
2015-04-22 00:15:54martin.panterlinkissue24019 messages
2015-04-22 00:15:52martin.pantercreate