python-peps/pep-0597.rst

137 lines
3.6 KiB
ReStructuredText
Raw Normal View History

PEP: 597
2020-02-04 04:35:06 -05:00
Title: Enable UTF-8 mode by default on Windows
Author: Inada Naoki <songofacandy@gmail.com>
Status: Draft
Type: Standards Track
Content-Type: text/x-rst
Created: 05-Jun-2019
2020-02-04 04:35:06 -05:00
Python-Version: 3.10
Abstract
========
2020-02-04 04:35:06 -05:00
This PEP proposes to make UTF-8 mode [#]_ enabled by default on
Windows.
The goal of this PEP is providing "UTF-8 by default" experience to
2020-02-04 04:35:06 -05:00
Windows users like Unix users.
Motivation
==========
2020-02-04 04:35:06 -05:00
UTF-8 is the best encoding nowdays
----------------------------------
2020-02-04 04:35:06 -05:00
Popular text editors like VS Code uses UTF-8 by default.
Even Microsoft Notepad uses UTF-8 by default since the Windows 10
May 2019 Update.
Additionally, the default encoding of Python source files is UTF-8.
2020-02-04 04:35:06 -05:00
We can assume that most Python programmers use UTF-8 for most text
files.
Python is one of the most popular first programming languages.
2020-02-04 04:35:06 -05:00
New programmers may not know about encoding. If the default encoding
for text files is UTF-8, they can learn about encoding when they need
to handle legacy encoding.
2020-02-04 04:35:06 -05:00
People assume the default encoding is UTF-8 already
---------------------------------------------------
2020-02-04 04:35:06 -05:00
Developers using macOS or Linux may forget that the default encoding
is not always UTF-8.
For example, ``long_description = open("README.md").read()`` in
2020-02-04 04:35:06 -05:00
``setup.py`` is a common mistake. Many Windows users can not install
the package if there is at least one emoji or any other non-ASCII
character in the ``README.md`` file.
2020-02-04 04:35:06 -05:00
Even Python experts assume that default encoding is UTF-8.
It creates bugs that happen only on Windows. See [#]_ [#]_.
2020-02-04 04:35:06 -05:00
Changing the default text encoding to UTF-8 will help many Windows
users.
Specification
=============
2020-02-04 04:35:06 -05:00
Enable UTF-8 mode on Windows unless it is disabled explicitly.
2020-02-04 04:35:06 -05:00
UTF-8 mode affects these areas:
2020-02-04 04:35:06 -05:00
* ``locale.getpreferredencoding`` returns "UTF-8".
2020-02-04 04:35:06 -05:00
* ``open``, ``subprocess.Popen``, ``pathlib.Path.read_text``,
``ZipFile.open``, and many other functions use UTF-8 when
the ``encoding`` option is omitted.
2020-02-04 04:35:06 -05:00
* The stdio uses "UTF-8" always.
2020-02-04 04:35:06 -05:00
* Console I/O uses "UTF-8" already [#]_. So this affects
only when the stdio are redirected.
2020-02-04 04:35:06 -05:00
On the other hand, UTF-8 mode doesn't affect to "mbcs" encoding.
Users can still use system encoding by chosing "mbcs" encoding
explicitly.
2020-02-04 04:35:06 -05:00
Backwards Compatibility
=======================
2020-02-04 04:35:06 -05:00
Some existing applications assuming the default text encoding is the
system encoding (a.k.a. ANSI encoding) will be broken by this change.
2020-02-04 04:35:06 -05:00
Users can disable the UTF-8 mode by environment variable
(``PYTHONUTF8=0``) or command line option (``-Xutf8=0``) for backward
compatibility.
2020-02-04 04:35:06 -05:00
Rejected Ideas
===============
2020-02-04 04:35:06 -05:00
Change the default encoding of TextIOWrapper to "UTF-8"
-------------------------------------------------------
2020-02-04 04:35:06 -05:00
This idea changed the default encoding to UTF-8 always, regardless of
platform, locale, and environment variables.
2020-02-04 04:35:06 -05:00
While this idea looks ideal in terms of consistency, it will cause
backward compatibility problems.
2020-02-04 04:35:06 -05:00
Utilizing the UTF-8 mode seems better than adding one more backward
compatibility option like ``PYTHONLEGACYWINDOWSSTDIO``.
Reference Implementation
========================
To be written.
References
==========
2020-02-04 04:35:06 -05:00
.. [#] `PEP 540 -- Add a new UTF-8 Mode <https://www.python.org/dev/peps/pep-0540/>`_
.. [#] https://github.com/pypa/packaging.python.org/pull/682
.. [#] https://bugs.python.org/issue33684
.. [#] `PEP 528 -- Change Windows console encoding to UTF-8 <https://www.python.org/dev/peps/pep-0528/>`_
Copyright
=========
This document has been placed in the public domain.
..
Local Variables:
mode: indented-text
indent-tabs-mode: nil
sentence-end-double-space: t
fill-column: 70
coding: utf-8
End: