New submission from Nick Coghlan:
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/
----------
messages: 193585
nosy: haypo, ncoghlan
priority: normal
severity: normal
status: open
title: File "name" attribute should always be a text string
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue18534>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com