From c658bedbc7b8a09a920c790e770c096a12757a66 Mon Sep 17 00:00:00 2001 From: Cool Guy Date: Fri, 20 Nov 2026 22:12:48 +0800 Subject: [PATCH 1/9] gh-148603: Update docstrings now UTF-8 is default --- Modules/_io/_iomodule.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 03e6fbe08889d4..07284711b4c328 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -94,10 +94,10 @@ mode. Other common values are 'w' for writing (truncating the file if it already exists), 'x' for creating and writing to a new file, and 'a' for appending (which on some Unix systems, means that all writes append to the end of the file regardless of the current seek position). -In text mode, if encoding is not specified the encoding used is platform -dependent: locale.getencoding() is called to get the current locale -encoding. (For reading and writing raw bytes use binary mode and leave -encoding unspecified.) The available modes are: +In text mode, if encoding is not specified UTF-8 is used by default; +if Python UTF-8 Mode is disabled, locale.getencoding() is called to get +the current locale encoding. (For reading and writing raw bytes use +binary mode and leave encoding unspecified.) The available modes are: ========= ========================================================== Character Meaning From c4df8beaf2ca970191a8dbbbd34c1cdac3ed9603 Mon Sep 17 00:00:00 2001 From: Lucas Cutecat Date: Fri, 20 Nov 2026 23:12:57 +0800 Subject: [PATCH 2/9] clinic generate --- Modules/_io/_iomodule.c | 2 +- Modules/_io/clinic/_iomodule.c.h | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 07284711b4c328..0e78a077be04f9 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -200,7 +200,7 @@ static PyObject * _io_open_impl(PyObject *module, PyObject *file, const char *mode, int buffering, const char *encoding, const char *errors, const char *newline, int closefd, PyObject *opener) -/*[clinic end generated code: output=aefafc4ce2b46dc0 input=b3cefa70bef404b3]*/ +/*[clinic end generated code: output=aefafc4ce2b46dc0 input=44463133cc1c2e32]*/ { size_t i; diff --git a/Modules/_io/clinic/_iomodule.c.h b/Modules/_io/clinic/_iomodule.c.h index 0547982cad48cc..b9bba33278dccd 100644 --- a/Modules/_io/clinic/_iomodule.c.h +++ b/Modules/_io/clinic/_iomodule.c.h @@ -28,10 +28,10 @@ PyDoc_STRVAR(_io_open__doc__, "it already exists), \'x\' for creating and writing to a new file, and\n" "\'a\' for appending (which on some Unix systems, means that all writes\n" "append to the end of the file regardless of the current seek position).\n" -"In text mode, if encoding is not specified the encoding used is platform\n" -"dependent: locale.getencoding() is called to get the current locale\n" -"encoding. (For reading and writing raw bytes use binary mode and leave\n" -"encoding unspecified.) The available modes are:\n" +"In text mode, if encoding is not specified UTF-8 is used by default;\n" +"if Python UTF-8 Mode is disabled, locale.getencoding() is called to get\n" +"the current locale encoding. (For reading and writing raw bytes use\n" +"binary mode and leave encoding unspecified.) The available modes are:\n" "\n" "========= ==========================================================\n" "Character Meaning\n" @@ -392,4 +392,4 @@ _io_open_code(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec exit: return return_value; } -/*[clinic end generated code: output=4570f4466d711d60 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e46243250c504342 input=a9049054013a1b77]*/ From b90fc61c66f5721cf36306ab54126787ec4c76ea Mon Sep 17 00:00:00 2001 From: Cool Guy Date: Sat, 21 Nov 2026 14:26:45 +0800 Subject: [PATCH 3/9] Apply methane suggestions Co-authored-by: Inada Naoki --- Modules/_io/_iomodule.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 0e78a077be04f9..40e6faf3e392c1 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -94,10 +94,7 @@ mode. Other common values are 'w' for writing (truncating the file if it already exists), 'x' for creating and writing to a new file, and 'a' for appending (which on some Unix systems, means that all writes append to the end of the file regardless of the current seek position). -In text mode, if encoding is not specified UTF-8 is used by default; -if Python UTF-8 Mode is disabled, locale.getencoding() is called to get -the current locale encoding. (For reading and writing raw bytes use -binary mode and leave encoding unspecified.) The available modes are: +The available modes are: ========= ========================================================== Character Meaning @@ -123,7 +120,8 @@ binary mode (appending 'b' to the mode argument) return contents as bytes objects without any decoding. In text mode (the default, or when 't' is appended to the mode argument), the contents of the file are returned as strings, the bytes having been first decoded using a -platform-dependent encoding or using the specified encoding if given. +'t' is appended to the mode argument), the contents of the file are +decoded using the encoding described above and returned as strings. buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to @@ -143,7 +141,11 @@ argument is given, the default buffering policy works as follows: encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent, but any encoding supported by Python can be -passed. See the codecs module for the list of supported encodings. +encoding is the name of the encoding used to decode or encode the file. +This should only be used in text mode. The default encoding is UTF-8; +if UTF-8 Mode is disabled, the encoding returned by +locale.getencoding() is used instead. See the codecs module for the +list of supported encodings. errors is an optional string that specifies how encoding errors are to be handled---this argument should not be used in binary mode. Pass From 2913e3a71883921dc9e744b27a915d221de1a013 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Sat, 21 Nov 2026 16:37:18 +0900 Subject: [PATCH 4/9] Fix text and binary mode documentation in _iomodule.c Clarified the description of file modes and encoding handling. --- Modules/_io/_iomodule.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 40e6faf3e392c1..1dac5aa3e19806 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -119,9 +119,7 @@ even when the underlying operating system doesn't. Files opened in binary mode (appending 'b' to the mode argument) return contents as bytes objects without any decoding. In text mode (the default, or when 't' is appended to the mode argument), the contents of the file are -returned as strings, the bytes having been first decoded using a -'t' is appended to the mode argument), the contents of the file are -decoded using the encoding described above and returned as strings. +decoded using the encoding described below and returned as strings. buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to @@ -138,9 +136,6 @@ argument is given, the default buffering policy works as follows: use line buffering. Other text files use the policy described above for binary files. -encoding is the name of the encoding used to decode or encode the -file. This should only be used in text mode. The default encoding is -platform dependent, but any encoding supported by Python can be encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is UTF-8; if UTF-8 Mode is disabled, the encoding returned by From 13591065bb037e862d3544ef172a9c9fee1beb2b Mon Sep 17 00:00:00 2001 From: Lucas Cutecat Date: Sat, 21 Nov 2026 20:01:12 +0800 Subject: [PATCH 5/9] clinic generate --- Modules/_io/_iomodule.c | 2 +- Modules/_io/clinic/_iomodule.c.h | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 1dac5aa3e19806..0d28fe24fa0b3a 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -197,7 +197,7 @@ static PyObject * _io_open_impl(PyObject *module, PyObject *file, const char *mode, int buffering, const char *encoding, const char *errors, const char *newline, int closefd, PyObject *opener) -/*[clinic end generated code: output=aefafc4ce2b46dc0 input=44463133cc1c2e32]*/ +/*[clinic end generated code: output=aefafc4ce2b46dc0 input=5a005681afa02242]*/ { size_t i; diff --git a/Modules/_io/clinic/_iomodule.c.h b/Modules/_io/clinic/_iomodule.c.h index b9bba33278dccd..462597078b77d9 100644 --- a/Modules/_io/clinic/_iomodule.c.h +++ b/Modules/_io/clinic/_iomodule.c.h @@ -28,10 +28,7 @@ PyDoc_STRVAR(_io_open__doc__, "it already exists), \'x\' for creating and writing to a new file, and\n" "\'a\' for appending (which on some Unix systems, means that all writes\n" "append to the end of the file regardless of the current seek position).\n" -"In text mode, if encoding is not specified UTF-8 is used by default;\n" -"if Python UTF-8 Mode is disabled, locale.getencoding() is called to get\n" -"the current locale encoding. (For reading and writing raw bytes use\n" -"binary mode and leave encoding unspecified.) The available modes are:\n" +"The available modes are:\n" "\n" "========= ==========================================================\n" "Character Meaning\n" @@ -56,8 +53,7 @@ PyDoc_STRVAR(_io_open__doc__, "binary mode (appending \'b\' to the mode argument) return contents as\n" "bytes objects without any decoding. In text mode (the default, or when\n" "\'t\' is appended to the mode argument), the contents of the file are\n" -"returned as strings, the bytes having been first decoded using a\n" -"platform-dependent encoding or using the specified encoding if given.\n" +"decoded using the encoding described below and returned as strings.\n" "\n" "buffering is an optional integer used to set the buffering policy.\n" "Pass 0 to switch buffering off (only allowed in binary mode), 1 to\n" @@ -74,10 +70,11 @@ PyDoc_STRVAR(_io_open__doc__, " use line buffering. Other text files use the policy described above\n" " for binary files.\n" "\n" -"encoding is the name of the encoding used to decode or encode the\n" -"file. This should only be used in text mode. The default encoding is\n" -"platform dependent, but any encoding supported by Python can be\n" -"passed. See the codecs module for the list of supported encodings.\n" +"encoding is the name of the encoding used to decode or encode the file.\n" +"This should only be used in text mode. The default encoding is UTF-8;\n" +"if UTF-8 Mode is disabled, the encoding returned by\n" +"locale.getencoding() is used instead. See the codecs module for the\n" +"list of supported encodings.\n" "\n" "errors is an optional string that specifies how encoding errors are to\n" "be handled---this argument should not be used in binary mode. Pass\n" @@ -392,4 +389,4 @@ _io_open_code(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec exit: return return_value; } -/*[clinic end generated code: output=e46243250c504342 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=517d977e17d38fce input=a9049054013a1b77]*/ From b151e07739198a3b7935608b1d42f3f2449f2d2b Mon Sep 17 00:00:00 2001 From: Lucas Cutecat Date: Sat, 21 Nov 2026 20:08:54 +0800 Subject: [PATCH 6/9] _pyio --- Lib/_pyio.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/_pyio.py b/Lib/_pyio.py index ec1b20d0426768..fd3ee4b11f5555 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -2095,7 +2095,10 @@ class TextIOWrapper(TextIOBase): r"""Character and line based layer over a BufferedIOBase object, buffer. encoding gives the name of the encoding that the stream will be - decoded or encoded with. It defaults to locale.getencoding(). + decoded or encoded with. It defaults to UTF-8; if UTF-8 Mode is + disabled, the encoding returned by locale.getencoding() is used + instead. See the codecs module for the list of supported + encodings. errors determines the strictness of encoding and decoding (see the codecs.register) and defaults to "strict". From dda00548bc5b926b0bd408cffa08724df4e19da0 Mon Sep 17 00:00:00 2001 From: Lucas Cutecat Date: Sat, 21 Nov 2026 20:19:17 +0800 Subject: [PATCH 7/9] fix _io/textio.c --- Modules/_io/textio.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 967392313bea20..2221f6d52cb5d0 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1150,7 +1150,10 @@ _io.TextIOWrapper.__init__ Character and line based layer over a BufferedIOBase object, buffer. encoding gives the name of the encoding that the stream will be -decoded or encoded with. It defaults to locale.getencoding(). +decoded or encoded with. It defaults to UTF-8; if UTF-8 Mode is +disabled, the encoding returned by locale.getencoding() is used +instead. See the codecs module for the list of supported +encodings. errors determines the strictness of encoding and decoding (see help(codecs.Codec) or the documentation for codecs.register) and From f33b97510788a49f3f97e3d07f506ac4d1ebda3b Mon Sep 17 00:00:00 2001 From: Lucas Cutecat Date: Sat, 21 Nov 2026 20:22:53 +0800 Subject: [PATCH 8/9] clinic generate --- Modules/_io/clinic/textio.c.h | 7 +++++-- Modules/_io/textio.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index 51e75d05061799..a63c2d953e8a25 100644 --- a/Modules/_io/clinic/textio.c.h +++ b/Modules/_io/clinic/textio.c.h @@ -441,7 +441,10 @@ PyDoc_STRVAR(_io_TextIOWrapper___init____doc__, "Character and line based layer over a BufferedIOBase object, buffer.\n" "\n" "encoding gives the name of the encoding that the stream will be\n" -"decoded or encoded with. It defaults to locale.getencoding().\n" +"decoded or encoded with. It defaults to UTF-8; if UTF-8 Mode is\n" +"disabled, the encoding returned by locale.getencoding() is used\n" +"instead. See the codecs module for the list of supported\n" +"encodings.\n" "\n" "errors determines the strictness of encoding and decoding (see\n" "help(codecs.Codec) or the documentation for codecs.register) and\n" @@ -1261,4 +1264,4 @@ _io_TextIOWrapper_buffer_get(PyObject *self, void *Py_UNUSED(context)) #define _IO_TEXTIOWRAPPER_BUFFER_GETSETDEF {"buffer", (getter)_io_TextIOWrapper_buffer_get, (setter)NULL, NULL}, -/*[clinic end generated code: output=f3dd3fff36cd2142 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=9c9a0b205b58bdc0 input=a9049054013a1b77]*/ diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 2221f6d52cb5d0..a8605d21879bc2 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1185,7 +1185,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, const char *encoding, PyObject *errors, const char *newline, int line_buffering, int write_through) -/*[clinic end generated code: output=72267c0c01032ed2 input=0f077220214c40a4]*/ +/*[clinic end generated code: output=72267c0c01032ed2 input=4f0bee5a0b2302fd]*/ { PyObject *raw, *codec_info = NULL; PyObject *res; From 5ecc8e6a4e24ecca495fedd8ba3d18262a4c727d Mon Sep 17 00:00:00 2001 From: Lucas Cutecat Date: Sat, 21 Nov 2026 20:26:22 +0800 Subject: [PATCH 9/9] fix probable grammar issue --- Lib/_pyio.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/_pyio.py b/Lib/_pyio.py index fd3ee4b11f5555..ed97263a7d65f7 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -2100,8 +2100,9 @@ class TextIOWrapper(TextIOBase): instead. See the codecs module for the list of supported encodings. - errors determines the strictness of encoding and decoding (see the - codecs.register) and defaults to "strict". + errors determines the strictness of encoding and decoding (see + help(codecs.Codec) or the documentation for codecs.register) and + defaults to "strict". newline can be None, '', '\n', '\r', or '\r\n'. It controls the handling of line endings. If it is None, universal newlines is