Skip to content
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

bpo-33601: Document for Py_UTF8Mode #7143

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 14 additions & 0 deletions Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,20 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
Set by the :option:`-u` option and the :envvar:`PYTHONUNBUFFERED`
environment variable.

.. c:var:: Py_UTF8Mode

Enable Cpython utf-8 mode, which ignores the locale settings, and
uses the UTF-8 encoding by default; changes `sys.stdin` and
`sys.stdout` error handlers to ``surrogateescape``. By default,
it is enabled in the POSIX locale.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation is incorrect. Extract of Python/bltinmodule.c:

/* UTF-8 mode (PEP 540): if equals to 1, use the UTF-8 encoding, and change
   stdin and stdout error handler to "surrogateescape". It is equal to
   -1 by default: unknown, will be set by Py_Main() */
int Py_UTF8Mode = -1;

I suggest:

  • If set to 1, enable the UTF-8 Mode
  • If set to 0, disable the UTF-8 Mode
  • If set to -1, look for the :envvar:PYTHONUTF8 environment variable and the :option:-X utf8 command line option

I would suggest to not document here the effects of the UTF-8 Mode.

Currently, the effects of the UTF-8 Mode are not documented. But I would prefer to not document it at 3 different places: C API doc, PYTHONUTF8 doc, -X utf8 doc.

I don't know what is the best place to document the UTF-8 Mode, but I would prefer to document it in a Python documentation (not in the C API).


Set by the :option:`-X` ``utf8`` option and the :envvar:`PYTHONUTF8`
environment variable.

See :pep:`540` for more details.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to add "the": See the :pep:540 ...


.. versionadded:: 3.7

.. c:var:: Py_VerboseFlag

Print a message each time a module is initialized, showing the place
Expand Down