[docs] [issue26369] unicode.decode and str.encode are unnecessarily confusing for non-ascii

Ben Spiller report at bugs.python.org
Thu May 12 07:42:07 EDT 2016


Ben Spiller added the comment:

I'm proposing that str.encode() should _not_ throw a 'decode' exception  for non-ascii characters and be effectively a no-op, to match what it already does for ascii characters - which therefore shouldn't break behavior anyone will be depending on. This could be achieved by passing the encoding parameter through to the implicit decode() call (which is where the exception is coming from it appears), rather than (arbitrarily and surprisingly) using "ascii" (which of course sometimes works and sometimes doesn't depending on the input string)

Does that make sense?

If someone can find the place in the code (sorry I tried and failed!) where str.encode('utf-8') is resulting in an implicit call to the equivalent of decode('ascii') (as suggested by the exception message) I think it'll be easier to discuss the details

----------

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


More information about the docs mailing list