Skip to content

Commit f402966

Browse files
authored
Merge branch 'python:main' into pyio-textiowrapper-seek
2 parents c8faf57 + 8d8b854 commit f402966

File tree

16 files changed

+85
-60
lines changed

16 files changed

+85
-60
lines changed

Lib/asyncio/futures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Future:
6262
# that it is not compatible by setting this to None.
6363
# - It is set by __iter__() below so that Task.__step() can tell
6464
# the difference between
65-
# `await Future()` or`yield from Future()` (correct) vs.
65+
# `await Future()` or `yield from Future()` (correct) vs.
6666
# `yield Future()` (incorrect).
6767
_asyncio_future_blocking = False
6868

Lib/test/test_builtin.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,14 +1567,12 @@ def test_open(self):
15671567

15681568
@unittest.skipIf(sys.flags.utf8_mode, "utf-8 mode is enabled")
15691569
def test_open_default_encoding(self):
1570-
old_environ = dict(os.environ)
1571-
try:
1570+
with EnvironmentVarGuard() as env:
15721571
# try to get a user preferred encoding different than the current
15731572
# locale encoding to check that open() uses the current locale
15741573
# encoding and not the user preferred encoding
15751574
for key in ('LC_ALL', 'LANG', 'LC_CTYPE'):
1576-
if key in os.environ:
1577-
del os.environ[key]
1575+
env.unset(key)
15781576

15791577
self.write_testfile()
15801578
current_locale_encoding = locale.getencoding()
@@ -1583,9 +1581,6 @@ def test_open_default_encoding(self):
15831581
fp = open(TESTFN, 'w')
15841582
with fp:
15851583
self.assertEqual(fp.encoding, current_locale_encoding)
1586-
finally:
1587-
os.environ.clear()
1588-
os.environ.update(old_environ)
15891584

15901585
@support.requires_subprocess()
15911586
def test_open_non_inheritable(self):

Lib/test/test_cmd_line_script.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,8 @@ def test_syntaxerror_invalid_escape_sequence_multi_line(self):
659659
stderr.splitlines()[-3:],
660660
[ b' foo = """\\q"""',
661661
b' ^^^^^^^^',
662-
b'SyntaxError: invalid escape sequence \'\\q\''
662+
b'SyntaxError: "\\q" is an invalid escape sequence. '
663+
b'Did you mean "\\\\q"? A raw string is also an option.'
663664
],
664665
)
665666

Lib/test/test_codeop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def test_warning(self):
282282
# Test that the warning is only returned once.
283283
with warnings_helper.check_warnings(
284284
('"is" with \'str\' literal', SyntaxWarning),
285-
("invalid escape sequence", SyntaxWarning),
285+
('"\\\\e" is an invalid escape sequence', SyntaxWarning),
286286
) as w:
287287
compile_command(r"'\e' is 0")
288288
self.assertEqual(len(w.warnings), 2)

Lib/test/test_doctest/test_doctest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2860,7 +2860,7 @@ def test_testfile(): r"""
28602860
>>> _colorize.COLORIZE = save_colorize
28612861
"""
28622862

2863-
class TestImporter(importlib.abc.MetaPathFinder, importlib.abc.ResourceLoader):
2863+
class TestImporter(importlib.abc.MetaPathFinder):
28642864

28652865
def find_spec(self, fullname, path, target=None):
28662866
return importlib.util.spec_from_file_location(fullname, path, loader=self)
@@ -2869,6 +2869,12 @@ def get_data(self, path):
28692869
with open(path, mode='rb') as f:
28702870
return f.read()
28712871

2872+
def exec_module(self, module):
2873+
raise ImportError
2874+
2875+
def create_module(self, spec):
2876+
return None
2877+
28722878
class TestHook:
28732879

28742880
def __init__(self, pathdir):

Lib/test/test_io.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,24 +2892,19 @@ def test_reconfigure_line_buffering(self):
28922892

28932893
@unittest.skipIf(sys.flags.utf8_mode, "utf-8 mode is enabled")
28942894
def test_default_encoding(self):
2895-
old_environ = dict(os.environ)
2896-
try:
2895+
with os_helper.EnvironmentVarGuard() as env:
28972896
# try to get a user preferred encoding different than the current
28982897
# locale encoding to check that TextIOWrapper() uses the current
28992898
# locale encoding and not the user preferred encoding
29002899
for key in ('LC_ALL', 'LANG', 'LC_CTYPE'):
2901-
if key in os.environ:
2902-
del os.environ[key]
2900+
env.unset(key)
29032901

29042902
current_locale_encoding = locale.getencoding()
29052903
b = self.BytesIO()
29062904
with warnings.catch_warnings():
29072905
warnings.simplefilter("ignore", EncodingWarning)
29082906
t = self.TextIOWrapper(b)
29092907
self.assertEqual(t.encoding, current_locale_encoding)
2910-
finally:
2911-
os.environ.clear()
2912-
os.environ.update(old_environ)
29132908

29142909
def test_encoding(self):
29152910
# Check the encoding attribute is always set, and valid

Lib/test/test_locale.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from decimal import Decimal
2-
from test.support import verbose, is_android, is_emscripten, is_wasi
2+
from test.support import verbose, is_android, is_emscripten, is_wasi, os_helper
33
from test.support.warnings_helper import check_warnings
44
from test.support.import_helper import import_fresh_module
55
from unittest import mock
@@ -499,25 +499,16 @@ def test_defaults_UTF8(self):
499499
else:
500500
orig_getlocale = None
501501

502-
orig_env = {}
503502
try:
504-
for key in ('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE'):
505-
if key in os.environ:
506-
orig_env[key] = os.environ[key]
507-
del os.environ[key]
503+
with os_helper.EnvironmentVarGuard() as env:
504+
for key in ('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE'):
505+
env.unset(key)
508506

509-
os.environ['LC_CTYPE'] = 'UTF-8'
510-
511-
with check_warnings(('', DeprecationWarning)):
512-
self.assertEqual(locale.getdefaultlocale(), (None, 'UTF-8'))
507+
env.set('LC_CTYPE', 'UTF-8')
513508

509+
with check_warnings(('', DeprecationWarning)):
510+
self.assertEqual(locale.getdefaultlocale(), (None, 'UTF-8'))
514511
finally:
515-
for k in orig_env:
516-
os.environ[k] = orig_env[k]
517-
518-
if 'LC_CTYPE' not in orig_env:
519-
del os.environ['LC_CTYPE']
520-
521512
if orig_getlocale is not None:
522513
_locale._getdefaultlocale = orig_getlocale
523514

Lib/test/test_string_literals.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ def test_eval_str_invalid_escape(self):
116116
warnings.simplefilter('always', category=SyntaxWarning)
117117
eval("'''\n\\z'''")
118118
self.assertEqual(len(w), 1)
119-
self.assertEqual(str(w[0].message), r"invalid escape sequence '\z'")
119+
self.assertEqual(str(w[0].message), r'"\z" is an invalid escape sequence. '
120+
r'Such sequences will not work in the future. '
121+
r'Did you mean "\\z"? A raw string is also an option.')
120122
self.assertEqual(w[0].filename, '<string>')
121123
self.assertEqual(w[0].lineno, 1)
122124

@@ -126,7 +128,8 @@ def test_eval_str_invalid_escape(self):
126128
eval("'''\n\\z'''")
127129
exc = cm.exception
128130
self.assertEqual(w, [])
129-
self.assertEqual(exc.msg, r"invalid escape sequence '\z'")
131+
self.assertEqual(exc.msg, r'"\z" is an invalid escape sequence. '
132+
r'Did you mean "\\z"? A raw string is also an option.')
130133
self.assertEqual(exc.filename, '<string>')
131134
self.assertEqual(exc.lineno, 1)
132135
self.assertEqual(exc.offset, 1)
@@ -153,7 +156,9 @@ def test_eval_str_invalid_octal_escape(self):
153156
eval("'''\n\\407'''")
154157
self.assertEqual(len(w), 1)
155158
self.assertEqual(str(w[0].message),
156-
r"invalid octal escape sequence '\407'")
159+
r'"\407" is an invalid octal escape sequence. '
160+
r'Such sequences will not work in the future. '
161+
r'Did you mean "\\407"? A raw string is also an option.')
157162
self.assertEqual(w[0].filename, '<string>')
158163
self.assertEqual(w[0].lineno, 1)
159164

@@ -163,7 +168,8 @@ def test_eval_str_invalid_octal_escape(self):
163168
eval("'''\n\\407'''")
164169
exc = cm.exception
165170
self.assertEqual(w, [])
166-
self.assertEqual(exc.msg, r"invalid octal escape sequence '\407'")
171+
self.assertEqual(exc.msg, r'"\407" is an invalid octal escape sequence. '
172+
r'Did you mean "\\407"? A raw string is also an option.')
167173
self.assertEqual(exc.filename, '<string>')
168174
self.assertEqual(exc.lineno, 1)
169175
self.assertEqual(exc.offset, 1)
@@ -205,7 +211,9 @@ def test_eval_bytes_invalid_escape(self):
205211
warnings.simplefilter('always', category=SyntaxWarning)
206212
eval("b'''\n\\z'''")
207213
self.assertEqual(len(w), 1)
208-
self.assertEqual(str(w[0].message), r"invalid escape sequence '\z'")
214+
self.assertEqual(str(w[0].message), r'"\z" is an invalid escape sequence. '
215+
r'Such sequences will not work in the future. '
216+
r'Did you mean "\\z"? A raw string is also an option.')
209217
self.assertEqual(w[0].filename, '<string>')
210218
self.assertEqual(w[0].lineno, 1)
211219

@@ -215,7 +223,8 @@ def test_eval_bytes_invalid_escape(self):
215223
eval("b'''\n\\z'''")
216224
exc = cm.exception
217225
self.assertEqual(w, [])
218-
self.assertEqual(exc.msg, r"invalid escape sequence '\z'")
226+
self.assertEqual(exc.msg, r'"\z" is an invalid escape sequence. '
227+
r'Did you mean "\\z"? A raw string is also an option.')
219228
self.assertEqual(exc.filename, '<string>')
220229
self.assertEqual(exc.lineno, 1)
221230

@@ -228,8 +237,9 @@ def test_eval_bytes_invalid_octal_escape(self):
228237
warnings.simplefilter('always', category=SyntaxWarning)
229238
eval("b'''\n\\407'''")
230239
self.assertEqual(len(w), 1)
231-
self.assertEqual(str(w[0].message),
232-
r"invalid octal escape sequence '\407'")
240+
self.assertEqual(str(w[0].message), r'"\407" is an invalid octal escape sequence. '
241+
r'Such sequences will not work in the future. '
242+
r'Did you mean "\\407"? A raw string is also an option.')
233243
self.assertEqual(w[0].filename, '<string>')
234244
self.assertEqual(w[0].lineno, 1)
235245

@@ -239,7 +249,8 @@ def test_eval_bytes_invalid_octal_escape(self):
239249
eval("b'''\n\\407'''")
240250
exc = cm.exception
241251
self.assertEqual(w, [])
242-
self.assertEqual(exc.msg, r"invalid octal escape sequence '\407'")
252+
self.assertEqual(exc.msg, r'"\407" is an invalid octal escape sequence. '
253+
r'Did you mean "\\407"? A raw string is also an option.')
243254
self.assertEqual(exc.filename, '<string>')
244255
self.assertEqual(exc.lineno, 1)
245256

Lib/test/test_unparse.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,9 @@ def test_multiquote_joined_string(self):
651651

652652
def test_backslash_in_format_spec(self):
653653
import re
654-
msg = re.escape("invalid escape sequence '\\ '")
654+
msg = re.escape('"\\ " is an invalid escape sequence. '
655+
'Such sequences will not work in the future. '
656+
'Did you mean "\\\\ "? A raw string is also an option.')
655657
with self.assertWarnsRegex(SyntaxWarning, msg):
656658
self.check_ast_roundtrip("""f"{x:\\ }" """)
657659
self.check_ast_roundtrip("""f"{x:\\n}" """)

Misc/NEWS.d/3.10.0b1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ result from ``entry_points()`` as deprecated.
941941

942942
..
943943
944-
.. gh: 47383
944+
.. gh-issue: 47383
945945
.. date: 2021-04-08-19-32-26
946946
.. nonce: YI1hdL
947947
.. section: Library

0 commit comments

Comments
 (0)