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 <1374556018.34.0.468152457131.issue18534@psf.upfronthosting.co.za>
In-reply-to
Content
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 "f.name" 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.


[1] http://lucumr.pocoo.org/2013/7/2/the-updated-guide-to-unicode/
History
Date User Action Args
2013-07-23 05:06:58ncoghlansetrecipients: + ncoghlan, vstinner
2013-07-23 05:06:58ncoghlansetmessageid: <1374556018.34.0.468152457131.issue18534@psf.upfronthosting.co.za>
2013-07-23 05:06:58ncoghlanlinkissue18534 messages
2013-07-23 05:06:57ncoghlancreate