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 <rep...@bugs.python.org>
<http://bugs.python.org/issue18373>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to