[Python-ideas] Strings can sometimes convert to bytes without an encoding

MRAB python at mrabarnett.plus.com
Tue Jun 14 20:17:02 EDT 2016


On 2016-06-14 23:58, Franklin? Lee wrote:
> Current behavior (3.5.1):
>     >>> bytes('')
>     Traceback (most recent call last):
>       File "<stdin>", line 1, in <module>
>     TypeError: string argument without an encoding
>
> Suggestion:
> If the character size is 1, the `bytes`/`bytearray` constructor
> doesn't need a specified encoding.
>
> High-level idea:
> If the string only has code points in range(128), encoding is optional
> (and useless anyway). The new error message could be
>     TypeError: non-ASCII string argument without an encoding
>
Why is the encoding is optional (and useless)? Are you assuming that the 
user will want 'ascii'?

-1



More information about the Python-ideas mailing list