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

Stephen J. Turnbull stephen at xemacs.org
Tue Jun 14 20:50:56 EDT 2016


Franklin? Lee writes:
 > 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.

-1

The current rule is simple, the error obvious.  The rule you propose
is not only more complex, but also not TOOWTDI.  Many use cases will
want the default encoding, not ASCII.

Also, YAGNI.  People who really truly do want ASCII because of wire
protocol elements that look like English words are likely to be
working at the bytes level and not using str at all, especially after
PEP 461.



More information about the Python-ideas mailing list