Issue 10702: bytes and bytearray methods are not documented (original) (raw)
I was persuaded there was already a bug open with a patch adding bytes and bytearray in the sequence methods table, but I can’t find it.
I can't find it either, but this issue is different. I propose renaming "String Methods" to "String, bytes and bytearray methods" and
str.capitalize() bytes.capitalize() bytearray.capitalize()
Return a copy of the string with its first character capitalized and the rest lowercased. [Discuss Unicode vs bytes details.]
BTW, the "For 8-bit strings, this method is locale-dependent." part is probably out of date because bytes.capitalize() seems to pass non-ASCII bytes through:
bytes([ord('è')]).capitalize()[0] == ord('è') True
and for unicode strings the operation is not locale dependent.
Hi, it seems to me that section 4.6.5. Bytes and Byte Array Methods covers this already. It says:
Bytes and bytearray objects, being “strings of bytes”, have all methods found on strings, with the exception of encode(), format() and isidentifier(), which do not make sense with these types. For converting the objects to strings, they have a decode() method.
Wherever one of these methods needs to interpret the bytes as characters (e.g. the is...() methods), the ASCII character set is assumed.
This section covers belpolsky's needs, ie a reader can, from this, understand that bytes have a capitalize method. However, I support
- Expanding this section to explain more clearly what the methods do to bytes
- Discuss unicode vs bytes details
- Mention bytes and bytearrays in 4.6.1 String Methods, because it is quite far away from 4.6.5
As for the suggestion of renaming, if we rename the section, we have to decide what to call a string/byte/bytearray object because it now says, for example, str.something(); also we have to document the encode and decode methods seperately because they are not common to strings and bytes.