Skip to content

Commit 775c36f

Browse files
committed
PEP 597: Revise docstring and warning text in text_encoding function
1 parent f64e046 commit 775c36f

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

pep-0597.rst

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,26 @@ except that ``io.TextIOWrapper`` doesn't emit ``EncodingWarning`` when
144144
A pure Python implementation will look like this::
145145

146146
def text_encoding(encoding, stacklevel=1):
147-
"""Helper function to choose the text encoding.
147+
"""A helper function to choose the text encoding.
148148

149149
When *encoding* is not None, just return it.
150-
Otherwise, return the default text encoding (i.e., "locale").
150+
Otherwise, return the default text encoding (i.e. "locale").
151151

152-
This function emits EncodingWarning if *encoding* is None and
153-
sys.flags.encoding_warning is true.
152+
This function emits an EncodingWarning if *encoding* is None and
153+
sys.flags.encoding_warning is True.
154154

155-
This function can be used in APIs having encoding=None option
156-
and pass it to TextIOWrapper or open.
157-
But please consider using encoding="utf-8" for new APIs.
155+
This function can be used in APIs with an encoding=None parameter
156+
that pass it to TextIOWrapper or open.
157+
However, please consider using encoding="utf-8" for new APIs.
158158
"""
159159
if encoding is None:
160160
if sys.flags.encoding_warning:
161161
import warnings
162-
warnings.warn("'encoding' option is omitted",
163-
EncodingWarning, stacklevel + 2)
162+
warnings.warn(
163+
"The 'encoding' argument was omitted; please "
164+
"explicitly specify one (e.g. 'utf-8'), or 'locale' "
165+
"to use the current system's locale encoding",
166+
EncodingWarning, stacklevel + 2)
164167
encoding = "locale"
165168
return encoding
166169

0 commit comments

Comments
 (0)