@@ -144,23 +144,26 @@ except that ``io.TextIOWrapper`` doesn't emit ``EncodingWarning`` when
144
144
A pure Python implementation will look like this::
145
145
146
146
def text_encoding(encoding, stacklevel=1):
147
- """Helper function to choose the text encoding.
147
+ """A helper function to choose the text encoding.
148
148
149
149
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").
151
151
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 .
154
154
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.
158
158
"""
159
159
if encoding is None:
160
160
if sys.flags.encoding_warning:
161
161
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)
164
167
encoding = "locale"
165
168
return encoding
166
169
0 commit comments