PEP 538: clarify sys.stderr error handler isn't changing

The previous wording suggested that all three standard streams
were affected by the proposed change to the default error handler.

Only stdin and stdout are affected - the default error handler for
stderr continues to be "backslashreplace"
This commit is contained in:
Nick Coghlan 2017-05-06 20:59:05 +10:00
parent 2fb53e7c1b
commit 4067701b85
1 changed files with 14 additions and 10 deletions

View File

@ -49,9 +49,9 @@ changed such that:
locale to the first available locale out of ``C.UTF-8``, ``C.utf8``, or locale to the first available locale out of ``C.UTF-8``, ``C.utf8``, or
``UTF-8`` ``UTF-8``
* ``Py_Initialize`` will be updated to treat these potential coercion target * ``Py_Initialize`` will be updated to treat these potential coercion target
locales the same way it already treats the ``C`` locale: the default standard locales the same way it already treats the ``C`` locale: the default ``stdin``
stream error handler for these locales will become ``surrogateescape`` (this & ``stdout`` error handler for these locales will become ``surrogateescape``
default can be overridden through ``PYTHONIOENCODING`` and (this default can be overridden through ``PYTHONIOENCODING`` and
``Py_SetStandardStreamEncoding`` as usual) ``Py_SetStandardStreamEncoding`` as usual)
* if ``Py_Initialize`` detects that the legacy ``C`` locale remains active * if ``Py_Initialize`` detects that the legacy ``C`` locale remains active
(e.g. none of ``C.UTF-8``, ``C.utf8`` or ``UTF-8`` (e.g. none of ``C.UTF-8``, ``C.utf8`` or ``UTF-8``
@ -508,9 +508,9 @@ Changes to the default error handling on the standard streams
------------------------------------------------------------- -------------------------------------------------------------
Since Python 3.5, CPython has defaulted to using ``surrogateescape`` on the Since Python 3.5, CPython has defaulted to using ``surrogateescape`` on the
standard streams (``sys.stdin``, ``sys.stdout``, ``sys.stderr``) when it standard streams (``sys.stdin``, ``sys.stdout``) when it detects that the
detects that the current locale is ``C`` and no specific error handled has current locale is ``C`` and no specific error handled has been set using
been set using either the ``PYTHONIOENCODING`` environment variable or the either the ``PYTHONIOENCODING`` environment variable or the
``Py_setStandardStreamEncoding`` API. For other locales, the default error ``Py_setStandardStreamEncoding`` API. For other locales, the default error
handler for the standard streams is ``strict``. handler for the standard streams is ``strict``.
@ -520,6 +520,9 @@ coercion target locales (``C.UTF-8``, ``C.utf8``, and ``UTF-8``) will be added
to the list of locales that use ``surrogateescape`` as their default error to the list of locales that use ``surrogateescape`` as their default error
handler for the standard streams. handler for the standard streams.
No changes are proposed to the default error handler for ``sys.stderr``: that
will continue to be ``backslashreplace``.
Changes to locale settings on Android Changes to locale settings on Android
------------------------------------- -------------------------------------
@ -597,11 +600,12 @@ By coercing the locale away from the legacy C default and its assumption of
ASCII as the preferred text encoding, this PEP also disables the implicit use ASCII as the preferred text encoding, this PEP also disables the implicit use
of the "surrogateescape" error handler on the standard IO streams that was of the "surrogateescape" error handler on the standard IO streams that was
introduced in Python 3.5 ([15_]), as well as the automatic use of introduced in Python 3.5 ([15_]), as well as the automatic use of
``surrogateescape`` when operating in PEP 540's UTF-8 mode. ``surrogateescape`` when operating in PEP 540's proposed UTF-8 mode.
Rather than introducing yet another configuration option to address that, Rather than introducing yet another configuration option to adjust that
this PEP proposes to extend the "surrogateescape" default to also apply to behaviour, this PEP instead proposes to extend the "surrogateescape" default
the three potential coercion target locales. for ``stdin`` and ``stderr`` error handling to also apply to the three
potential coercion target locales.
The aim of this behaviour is to attempt to ensure that operating system The aim of this behaviour is to attempt to ensure that operating system
provided text values are typically able to be transparently passed through a provided text values are typically able to be transparently passed through a