PEP 597: Fixup (#1827)

This commit is contained in:
Inada Naoki 2021-02-21 16:01:52 +09:00 committed by GitHub
parent 35a0204848
commit b643690860
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 12 deletions

View File

@ -1,8 +1,7 @@
PEP: 597 PEP: 597
Title: Add optional EncodingWarning Title: Add optional EncodingWarning
Last-Modified: 30-Jan-2021 Last-Modified: 20-Feb-2021
Author: Inada Naoki <songofacandy@gmail.com> Author: Inada Naoki <songofacandy@gmail.com>
Discussions-To: https://discuss.python.org/t/3880
Status: Draft Status: Draft
Type: Standards Track Type: Standards Track
Content-Type: text/x-rst Content-Type: text/x-rst
@ -63,7 +62,7 @@ Explicit way to use locale-specific encoding
``open(filename)`` isn't explicit about which encoding is expected: ``open(filename)`` isn't explicit about which encoding is expected:
* Expects ASCII (not a bug, but inefficient on Windows) * Expects ASCII (not a bug, but inefficient on Windows)
* Expects UTF-8 (bug or platform specific script) * Expects UTF-8 (bug or platform-specific script)
* Expects the locale encoding. * Expects the locale encoding.
In this point of view, ``open(filename)`` is not readable. In this point of view, ``open(filename)`` is not readable.
@ -83,13 +82,13 @@ the default text encoding to UTF-8 in the future.
But this change will affect many applications and libraries. If we But this change will affect many applications and libraries. If we
start emitting ``DeprecationWarning`` everywhere ``encoding`` option start emitting ``DeprecationWarning`` everywhere ``encoding`` option
is omitted by default, it will be too noisy and painful. is omitted, it will be too noisy and painful.
Although this PEP doesn't propose to change the default encoding, Although this PEP doesn't propose to change the default encoding,
this PEP will the change: this PEP will help the change:
* Reduce the number of omitted ``encoding`` option in many libraries * Reduce the number of omitted ``encoding`` options in many libraries
before emitting the warning by default. before we start emitting the ``DeprecationWarning`` by default.
* Users will be able to use ``encoding="locale"`` option to suppress * Users will be able to use ``encoding="locale"`` option to suppress
the warning without dropping Python 3.10 support. the warning without dropping Python 3.10 support.
@ -111,13 +110,13 @@ Options to enable the warning
``-X warn_default_encoding`` option and the ``-X warn_default_encoding`` option and the
``PYTHONWARNDEFAULTENCODING`` environment variable are added. They ``PYTHONWARNDEFAULTENCODING`` environment variable are added. They
are used to enable the ``EncodingWarning``. are used to enable ``EncodingWarning``.
``sys.flags.encoding_warning`` is also added. The flag represents ``sys.flags.encoding_warning`` is also added. The flag represents
``EncodingWarning`` is enabled. ``EncodingWarning`` is enabled.
When the option is enabled, ``io.TextIOWrapper()``, ``open()``, and When the option is enabled, ``io.TextIOWrapper()``, ``open()``, and
other modules using them will emit ``EncodingWarning`` when other modules using them will emit ``EncodingWarning`` when the
``encoding`` is omitted. ``encoding`` is omitted.
Since ``EncodingWarning`` is a subclass of ``Warning``, they are Since ``EncodingWarning`` is a subclass of ``Warning``, they are
@ -272,6 +271,10 @@ https://github.com/python/cpython/pull/19481
Discussions Discussions
=========== ===========
The latest discussion thread is:
https://mail.python.org/archives/list/python-dev@python.org/thread/SFYUP2TWD5JZ5KDLVSTZ44GWKVY4YNCV/
* Why not implement this in linters? * Why not implement this in linters?
* ``encoding="locale"`` and ``io.text_encoding()`` must be in * ``encoding="locale"`` and ``io.text_encoding()`` must be in
@ -290,7 +293,7 @@ Discussions
* For example, I find [7]_ and [8]_ by running * For example, I find [7]_ and [8]_ by running
``pip install -U pip`` and find [9]_ by running ``tox`` ``pip install -U pip`` and find [9]_ by running ``tox``
with the reference implementation. It demonstrates how this with the reference implementation. It demonstrates how this
option find potential issues. option can be used to find potential issues.
References References
@ -332,12 +335,10 @@ Copyright
This document is placed in the public domain or under the This document is placed in the public domain or under the
CC0-1.0-Universal license, whichever is more permissive. CC0-1.0-Universal license, whichever is more permissive.
.. ..
Local Variables: Local Variables:
mode: indented-text mode: indented-text
indent-tabs-mode: nil indent-tabs-mode: nil
sentence-end-double-space: t
fill-column: 70 fill-column: 70
coding: utf-8 coding: utf-8
End: End: