Skip to content

Commit 814a303

Browse files
gh-148603: Update docstrings now UTF-8 is default (#162327)
1 parent ecab19d commit 814a303

5 files changed

Lines changed: 34 additions & 30 deletions

File tree

‎Lib/_pyio.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,10 +2100,14 @@ class TextIOWrapper(TextIOBase):
21002100
r"""Character and line based layer over a BufferedIOBase object, buffer.
21012101
21022102
encoding gives the name of the encoding that the stream will be
2103-
decoded or encoded with. It defaults to locale.getencoding().
2104-
2105-
errors determines the strictness of encoding and decoding (see the
2106-
codecs.register) and defaults to "strict".
2103+
decoded or encoded with. It defaults to UTF-8; if UTF-8 Mode is
2104+
disabled, the encoding returned by locale.getencoding() is used
2105+
instead. See the codecs module for the list of supported
2106+
encodings.
2107+
2108+
errors determines the strictness of encoding and decoding (see
2109+
help(codecs.Codec) or the documentation for codecs.register) and
2110+
defaults to "strict".
21072111
21082112
newline can be None, '', '\n', '\r', or '\r\n'. It controls the
21092113
handling of line endings. If it is None, universal newlines is

‎Modules/_io/_iomodule.c‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,7 @@ mode. Other common values are 'w' for writing (truncating the file if
9494
it already exists), 'x' for creating and writing to a new file, and
9595
'a' for appending (which on some Unix systems, means that all writes
9696
append to the end of the file regardless of the current seek position).
97-
In text mode, if encoding is not specified the encoding used is platform
98-
dependent: locale.getencoding() is called to get the current locale
99-
encoding. (For reading and writing raw bytes use binary mode and leave
100-
encoding unspecified.) The available modes are:
97+
The available modes are:
10198
10299
========= ==========================================================
103100
Character Meaning
@@ -122,8 +119,7 @@ even when the underlying operating system doesn't. Files opened in
122119
binary mode (appending 'b' to the mode argument) return contents as
123120
bytes objects without any decoding. In text mode (the default, or when
124121
't' is appended to the mode argument), the contents of the file are
125-
returned as strings, the bytes having been first decoded using a
126-
platform-dependent encoding or using the specified encoding if given.
122+
decoded using the encoding described below and returned as strings.
127123
128124
buffering is an optional integer used to set the buffering policy.
129125
Pass 0 to switch buffering off (only allowed in binary mode), 1 to
@@ -140,10 +136,11 @@ argument is given, the default buffering policy works as follows:
140136
use line buffering. Other text files use the policy described above
141137
for binary files.
142138
143-
encoding is the name of the encoding used to decode or encode the
144-
file. This should only be used in text mode. The default encoding is
145-
platform dependent, but any encoding supported by Python can be
146-
passed. See the codecs module for the list of supported encodings.
139+
encoding is the name of the encoding used to decode or encode the file.
140+
This should only be used in text mode. The default encoding is UTF-8;
141+
if UTF-8 Mode is disabled, the encoding returned by
142+
locale.getencoding() is used instead. See the codecs module for the
143+
list of supported encodings.
147144
148145
errors is an optional string that specifies how encoding errors are to
149146
be handled---this argument should not be used in binary mode. Pass
@@ -200,7 +197,7 @@ static PyObject *
200197
_io_open_impl(PyObject *module, PyObject *file, const char *mode,
201198
int buffering, const char *encoding, const char *errors,
202199
const char *newline, int closefd, PyObject *opener)
203-
/*[clinic end generated code: output=aefafc4ce2b46dc0 input=b3cefa70bef404b3]*/
200+
/*[clinic end generated code: output=aefafc4ce2b46dc0 input=5a005681afa02242]*/
204201
{
205202
size_t i;
206203

‎Modules/_io/clinic/_iomodule.c.h‎

Lines changed: 8 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Modules/_io/clinic/textio.c.h‎

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Modules/_io/textio.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,10 @@ _io.TextIOWrapper.__init__
11501150
Character and line based layer over a BufferedIOBase object, buffer.
11511151
11521152
encoding gives the name of the encoding that the stream will be
1153-
decoded or encoded with. It defaults to locale.getencoding().
1153+
decoded or encoded with. It defaults to UTF-8; if UTF-8 Mode is
1154+
disabled, the encoding returned by locale.getencoding() is used
1155+
instead. See the codecs module for the list of supported
1156+
encodings.
11541157
11551158
errors determines the strictness of encoding and decoding (see
11561159
help(codecs.Codec) or the documentation for codecs.register) and
@@ -1182,7 +1185,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
11821185
const char *encoding, PyObject *errors,
11831186
const char *newline, int line_buffering,
11841187
int write_through)
1185-
/*[clinic end generated code: output=72267c0c01032ed2 input=0f077220214c40a4]*/
1188+
/*[clinic end generated code: output=72267c0c01032ed2 input=4f0bee5a0b2302fd]*/
11861189
{
11871190
PyObject *raw, *codec_info = NULL;
11881191
PyObject *res;

0 commit comments

Comments
 (0)