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 vstinner
Recipients benjamin.peterson, terry.reedy, vstinner
Date 2010-10-15.23:17:36
SpamBayes Score 6.185178e-05
Marked as misclassified No
Message-id <1287184657.96.0.471896442106.issue10114@psf.upfronthosting.co.za>
In-reply-to
Content
> I do not see what filesystem encodings, or any other encoding 
> to bytes should really have to do with the [code.co_filename].

co_filename attribute is used to display the traceback: Python opens the related file, read the source code line and display it. On Windows, co_filename is directly used because Windows accepts unicode for filenames. But on other OSes, you have to encode the filename to the filesystem encoding.

If your filesystem encoding is 'ascii' (eg. C locale) and co_filename is a non-ascii filename (eg. 'test_é.py'), encode co_filename will raise a UnicodeEncodeError. You can test it simply by using os.fsencode():

$ ./python 
Python 3.2a3+ (py3k:85551:85553M, Oct 16 2010, 00:54:03) 
>>> import sys; sys.getfilesystemencoding()
'utf-8'
>>> import os; os.fsencode('é')
b'\xc3\xa9'

$ LANG= ./python 
Python 3.2a3+ (py3k:85551:85553M, Oct 16 2010, 00:54:03) 
>>> import sys; sys.getfilesystemencoding()
'ascii'
>>> import os; os.fsencode('\xe9')
...
UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' ...

Said differently, co_filename should be encodable to the filesystem encoding (os.fsencode(co_filename) should not raise an error).
History
Date User Action Args
2010-10-15 23:17:38vstinnersetrecipients: + vstinner, terry.reedy, benjamin.peterson
2010-10-15 23:17:37vstinnersetmessageid: <1287184657.96.0.471896442106.issue10114@psf.upfronthosting.co.za>
2010-10-15 23:17:36vstinnerlinkissue10114 messages
2010-10-15 23:17:36vstinnercreate