[docs] [issue13538] Improve doc for str(bytesobject)

Ezio Melotti report at bugs.python.org
Tue Oct 16 11:58:25 CEST 2012


Ezio Melotti added the comment:

+              str(bytes, encoding[, errors='strict'])
+              str(bytes, errors[, encoding='utf-8'])

Why not simply str(bytes, encoding='utf-8', errors='strict')? (Your signature suggests that str(b'abc', 'strict') should work.)

+   the string itself.  This behavior differs from :func:`repr` in that the

I'm not sure this is the right place where to explain the differences between __str__ and __repr__ (or maybe it is?).  Also doesn't str() falls back on __repr__ if __str__ is missing?  Does :meth:`__str__` link to object.__str__?

+   If *encoding* or *errors* is given,

and/or

+   (or :class:`bytearray`) object, then :func:`str` calls

I would use 'is equivalent to', rather than 'calls'.

+   :meth:`bytes.decode(encoding, errors) <bytes.decode>` on the object
+   and returns the value.  Otherwise, the bytes object underlying the buffer
+   object is obtained before calling :meth:`bytes.decode() <bytes.decode>`.

:meth:`bytes.decode` should be enough.

+   Passing a :func:`bytes <bytes>`

:func:`bytes` should be enough (if it isn't, maybe you want :func:`.bytes`).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13538>
_______________________________________


More information about the docs mailing list