Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions pep-0686.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Status: Draft
Type: Standards Track
Content-Type: text/x-rst
Created: 18-Mar-2022
Python-Version: 3.12
Python-Version: 3.13
Post-History: `18-Mar-2022 <https://discuss.python.org/t/14435>`__


Expand Down Expand Up @@ -55,14 +55,18 @@ User can still disable UTF-8 mode by setting ``PYTHONUTF8=0`` or ``-X utf8=0``.
``locale.get_encoding()``
-------------------------

Add ``locale.get_encoding()``. It is same to
``locale.getpreferredencoding(False)`` except it don't follow UTF-8 mode.
Currently, ``TextIOWrapper`` uses ``locale.getpreferredencoding(False)``
when ``encoding="locale"`` option is specified. It is ``"UTF-8"`` in UTF-8 mode.

This API will be used by ``io.TextIOWrapper`` to support ``encoding="locale"``
option.
This behavior is inconsistent with the :pep:`597` motivation.
``TextIOWrapper`` should use locale encoding when ``encoding="locale"`` is
passed before/after the default encoding is changed to UTF-8.

This change will be released in Python 3.11 so that users can prepare before
UTF-8 mode is enabled by default.
To fix this inconsistency, we will add ``locale.get_encoding()``. It is same
to ``locale.getpreferredencoding(False)`` but it ignore the UTF-8 mode.

This change will be released in Python 3.11 so that users can use UTF-8 mode
that is same to Python 3.13.


Backward Compatibility
Expand Down