This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: allow str(bytes) raises an exception to be controlled programmatically
Type: enhancement Stage:
Components: Unicode Versions: Python 3.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: dholth, ezio.melotti, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2016-05-27 02:35 by dholth, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
strbytes.patch dholth, 2016-05-27 02:35 review
Messages (3)
msg266465 - (view) Author: Daniel Holth (dholth) * Date: 2016-05-27 02:35
When I discovered str(b'bytes') in my Python 3 program was causing errors to be serialized to disk, I was unhappy. It turns out there is a command line option to turn it off, but the vulnerable serialization code is not going to be able to set that argument; or the one-argument-per-shebang limit we have in Linux was already used for something else.

Instead, provide a threadlocal variable that causes str(bytes) to raise. A context manager makes it simple to use for just a portion of your code:

with string.StrBytesRaises():
   no_str_bytes_here()

If not set or False then Python behaves as before.
msg266474 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-05-27 04:18
Isn't this a duplicate of issue18373?
msg266492 - (view) Author: Daniel Holth (dholth) * Date: 2016-05-27 12:41
Continuing discussion in the older bug
History
Date User Action Args
2022-04-11 14:58:31adminsetgithub: 71321
2016-05-27 12:41:43dholthsetstatus: open -> closed
resolution: duplicate
messages: + msg266492
2016-05-27 04:18:05serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg266474
2016-05-27 02:35:15dholthcreate