[issue18373] let code force str(bytes) to raise an exception

Daniel Holth report at bugs.python.org
Fri May 27 08:54:45 EDT 2016


Daniel Holth added the comment:

Better to continue discussion here.

Attached is my second, simpler version of the feature. A context manager is included:

with string.StrBytesRaises():
    str(b'bytes')

# raises an exception

In a normal program, you might just set the flag to True, but in a library that has no hope of setting the -bb flag you might use it during serialization rather than checking isinstance() on all input.

----------
title: implement sys.get/setbyteswarningflag() -> let code force str(bytes) to raise an exception
versions: +Python 3.6 -Python 3.5
Added file: http://bugs.python.org/file43029/strbytes.patch

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


More information about the Python-bugs-list mailing list