Skip to content

Commit 8001775

Browse files
authored
bpo-43651: Fix test_compileall with PEP 597 (GH-25128)
1 parent c0ec448 commit 8001775

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

Lib/compileall.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ def main():
407407
# if flist is provided then load it
408408
if args.flist:
409409
try:
410-
with (sys.stdin if args.flist=='-' else open(args.flist)) as f:
410+
with (sys.stdin if args.flist=='-' else
411+
open(args.flist, encoding="utf-8")) as f:
411412
for line in f:
412413
compile_dests.append(line.strip())
413414
except OSError:

Lib/multiprocessing/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def _close_stdin():
419419
try:
420420
fd = os.open(os.devnull, os.O_RDONLY)
421421
try:
422-
sys.stdin = open(fd, closefd=False)
422+
sys.stdin = open(fd, encoding="utf-8", closefd=False)
423423
except:
424424
os.close(fd)
425425
raise

Lib/test/test_compileall.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def setUp(self):
5858
self.directory = tempfile.mkdtemp()
5959
self.source_path = os.path.join(self.directory, '_test.py')
6060
self.bc_path = importlib.util.cache_from_source(self.source_path)
61-
with open(self.source_path, 'w') as file:
61+
with open(self.source_path, 'w', encoding="utf-8") as file:
6262
file.write('x = 123\n')
6363
self.source_path2 = os.path.join(self.directory, '_test2.py')
6464
self.bc_path2 = importlib.util.cache_from_source(self.source_path2)
@@ -73,7 +73,7 @@ def tearDown(self):
7373

7474
def add_bad_source_file(self):
7575
self.bad_source_path = os.path.join(self.directory, '_test_bad.py')
76-
with open(self.bad_source_path, 'w') as file:
76+
with open(self.bad_source_path, 'w', encoding="utf-8") as file:
7777
file.write('x (\n')
7878

7979
def timestamp_metadata(self):
@@ -164,7 +164,7 @@ def test_no_pycache_in_non_package(self):
164164
data_file = os.path.join(data_dir, 'file')
165165
os.mkdir(data_dir)
166166
# touch data/file
167-
with open(data_file, 'w'):
167+
with open(data_file, 'wb'):
168168
pass
169169
compileall.compile_file(data_file)
170170
self.assertFalse(os.path.exists(os.path.join(data_dir, '__pycache__')))
@@ -440,8 +440,7 @@ def setUpClass(cls):
440440
if not directory.is_dir():
441441
directory.mkdir()
442442
directory_created = True
443-
with path.open('w') as file:
444-
file.write('# for test_compileall')
443+
path.write_text('# for test_compileall', encoding="utf-8")
445444
except OSError:
446445
sys_path_writable = False
447446
break
@@ -704,7 +703,7 @@ def test_include_file_with_arg(self):
704703
f2 = script_helper.make_script(self.pkgdir, 'f2', '')
705704
f3 = script_helper.make_script(self.pkgdir, 'f3', '')
706705
f4 = script_helper.make_script(self.pkgdir, 'f4', '')
707-
with open(os.path.join(self.directory, 'l1'), 'w') as l1:
706+
with open(os.path.join(self.directory, 'l1'), 'w', encoding="utf-8") as l1:
708707
l1.write(os.path.join(self.pkgdir, 'f1.py')+os.linesep)
709708
l1.write(os.path.join(self.pkgdir, 'f2.py')+os.linesep)
710709
self.assertRunOK('-i', os.path.join(self.directory, 'l1'), f4)
@@ -718,7 +717,7 @@ def test_include_file_no_arg(self):
718717
f2 = script_helper.make_script(self.pkgdir, 'f2', '')
719718
f3 = script_helper.make_script(self.pkgdir, 'f3', '')
720719
f4 = script_helper.make_script(self.pkgdir, 'f4', '')
721-
with open(os.path.join(self.directory, 'l1'), 'w') as l1:
720+
with open(os.path.join(self.directory, 'l1'), 'w', encoding="utf-8") as l1:
722721
l1.write(os.path.join(self.pkgdir, 'f2.py')+os.linesep)
723722
self.assertRunOK('-i', os.path.join(self.directory, 'l1'))
724723
self.assertNotCompiled(f1)

0 commit comments

Comments
 (0)