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.

Author ncoghlan
Recipients ncoghlan, vstinner
Date 2013-07-23.05:06:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Currently, if a byte sequence is passed to open() as the file name, the resulting file will have that object as its name:

>>> open(os.path.expanduser(b"~/.hgrc"))
<_io.TextIOWrapper name=b'/home/ncoghlan/.hgrc' mode='r' encoding='UTF-8'>
>>> open(os.path.expanduser("~/.hgrc"))
<_io.TextIOWrapper name='/home/ncoghlan/.hgrc' mode='r' encoding='UTF-8'>

As documented in a recent post from Armin Ronacher [1], this causes the "bytes" to leak out to the public API of the file, causing problems since user code can't assume that "" is a string.

When bytes are passed to open() as the filename, os.fsdecode should be used to convert them to a text string before storing them in the name attribute.

Date User Action Args
2013-07-23 05:06:58ncoghlansetrecipients: + ncoghlan, vstinner
2013-07-23 05:06:58ncoghlansetmessageid: <>
2013-07-23 05:06:58ncoghlanlinkissue18534 messages
2013-07-23 05:06:57ncoghlancreate