Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
GH-133711: Enable UTF-8 mode by default (PEP 686)#133712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
fc19177c706cfaf095ab0ff066b1abfb864f40b9863226e1db83c966b56e01b3da6bf29b3ebf76ecea69e87ce6c3130318File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1006,6 +1006,9 @@ UTF-8 mode | ||
| ========== | ||
| .. versionadded:: 3.7 | ||
| .. versionchanged:: next | ||
| Python UTF-8 mode is now enabled by default (:pep:`686`). | ||
vstinner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| Windows still uses legacy encodings for the system encoding (the ANSI Code | ||
| Page). Python uses it for the default encoding of text files (e.g. | ||
| @@ -1014,20 +1017,22 @@ Page). Python uses it for the default encoding of text files (e.g. | ||
| This may cause issues because UTF-8 is widely used on the internet | ||
| and most Unix systems, including WSL (Windows Subsystem for Linux). | ||
| You can use the :ref:`Python UTF-8 Mode <utf8-mode>` to change the default text | ||
| encoding to UTF-8. You can enable the :ref:`Python UTF-8 Mode <utf8-mode>` via | ||
| the ``-X utf8`` command line option, or the ``PYTHONUTF8=1`` environment | ||
| variable. See :envvar:`PYTHONUTF8` for enabling UTF-8 mode, and | ||
| :ref:`setting-envvars` for how to modify environment variables. | ||
| When the :ref:`Python UTF-8 Mode <utf8-mode>` is enabled, you can still use the | ||
| The :ref:`Python UTF-8 Mode <utf8-mode>`, enabled by default, can help by | ||
| changing the default text encoding to UTF-8. | ||
| When the :ref:`UTF-8 mode <utf8-mode>` is enabled, you can still use the | ||
| system encoding (the ANSI Code Page) via the "mbcs" codec. | ||
| Note that adding ``PYTHONUTF8=1`` to the default environment variables | ||
| will affect all Python 3.7+ applications on your system. | ||
| If you have any Python 3.7+ applications which rely on the legacy | ||
| system encoding, it is recommended to set the environment variable | ||
| temporarily or use the ``-X utf8`` command line option. | ||
| You can disable the :ref:`Python UTF-8 Mode <utf8-mode>` via | ||
| the ``-X utf8=0`` command line option, or the ``PYTHONUTF8=0`` environment | ||
| variable. See :envvar:`PYTHONUTF8` for disabling UTF-8 mode, and | ||
| :ref:`setting-envvars` for how to modify environment variables. | ||
| .. hint:: | ||
| Adding ``PYTHONUTF8={0,1}`` to the default environment variables | ||
| will affect all Python 3.7+ applications on your system. | ||
| If you have any Python 3.7+ applications which rely on the legacy | ||
| system encoding, it is recommended to set the environment variable | ||
| temporarily or use the ``-X utf8`` command line option. | ||
| .. note:: | ||
| Even when UTF-8 mode is disabled, Python uses UTF-8 by default | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -172,11 +172,35 @@ production systems where traditional profiling approaches would be too intrusive | ||
| Other language changes | ||
| ====================== | ||
| * Python now uses UTF-8_ as the default encoding, independent of the system's | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might mention the UTF-8 Mode earlier since it has other side effects documented in the UTF-8 Mode section, such as changing sys.stdout error handler and ignoring the locale encoding. Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "default encoding" is UTF-8 since Python 3.0. (e.g. | ||
| environment. This means that I/O operations without an explicit encoding, | ||
| e.g. ``open('flying-circus.txt')``, will use UTF-8. | ||
| UTF-8 is a widely-supported Unicode_ character encoding that has become a | ||
| *de facto* standard for representing text, including nearly every webpage | ||
| on the internet, many common file formats, programming languages, and more. | ||
| This only applies when no ``encoding`` argument is given. For best | ||
| compatibility between versions of Python, ensure that an explicit ``encoding`` | ||
| argument is always provided. The :ref:`opt-in encoding warning <io-encoding-warning>` | ||
| can be used to identify code that may be affected by this change. | ||
| The special special ``encoding='locale'`` argument uses the current locale | ||
| encoding, and has been supported since Python 3.10. | ||
| To retain the previous behaviour, Python's UTF-8 mode may be disabled with | ||
| the :envvar:`PYTHONUTF8=0 <PYTHONUTF8>` environment variable or the | ||
| :option:`-X utf8=0 <-X>` command line option. | ||
| .. seealso:: :pep:`686` for further details. | ||
| .. _UTF-8: https://en.wikipedia.org/wiki/UTF-8 | ||
| .. _Unicode: https://home.unicode.org/ | ||
| (Contributed by Adam Turner in :gh:`133711`; PEP 686 written by Inada Naoki.) | ||
| * Several error messages incorrectly using the term "argument" have been corrected. | ||
| (Contributed by Stan Ulbrych in :gh:`133382`.) | ||
| New modules | ||
| =========== | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Implement :pep:`686`: Enable :ref:`Python UTF-8 Mode <utf8-mode>` by | ||
| default. Patch by Adam Turner. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.