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 serhiy.storchaka
Recipients methane, serhiy.storchaka, vstinner
Date 2020-06-21.11:04:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1592737455.62.0.0102457706835.issue41063@roundup.psfhosted.org>
In-reply-to
Content
Many tests use open() with the locale encoding for writing or reading files. They are passed because the written and read data a ASCII, and file paths are ASCII. But they do not test the case of non-ASCII data and file paths. In general, most of uses of the locale encoding should be changed.

1. In some cases it is enough to open the file in binary mode. For example when create an empty file, or use just fileno of the opened file.

2. In some cases the file should be opened in binary mode. For example, when compile the content of the file or parse it as XML, because the correct encoding is determined by the content (BOM, encoding coockie, XML declaration).

3. tokenize.open() or tokenize.detect_encoding() should be used when we read a Python source as a text.

4. os.fsdecode() and os.fsencode() may be used if the test file contains file paths and is read by bash or other external program.

5. encoding='ascii' should be specified if the test data always ASCII-only.

6. encoding='utf-8' should be specified if the test data can contain arbitrary Unicode characters.

7. Encoding different from 'ascii', 'latin1' and 'utf-8' should be used if arbitrary encodings should be supported.

8. Implicit locale encoding should be only used if the test is purposed to test the implicit encoding.

It is preferable to add non-ASCII characters in the test data.

I am working on a large patch for this (>50% is ready). Some parts of it may be extracted as separate PRs, and the rest will be exposed as a large PR. If changes are required not only in tests. separate issues will be opened.
History
Date User Action Args
2020-06-21 11:04:15serhiy.storchakasetrecipients: + serhiy.storchaka, vstinner, methane
2020-06-21 11:04:15serhiy.storchakasetmessageid: <1592737455.62.0.0102457706835.issue41063@roundup.psfhosted.org>
2020-06-21 11:04:15serhiy.storchakalinkissue41063 messages
2020-06-21 11:04:15serhiy.storchakacreate