Skip to content

Commit e37767b

Browse files
bpo-38722: Runpy use io.open_code() (GH-17234)
https://bugs.python.org/issue38722 Automerge-Triggered-By: @taleinat (cherry picked from commit e243bae) Co-authored-by: jsnklln <[email protected]>
1 parent 47db743 commit e37767b

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Lib/runpy.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import sys
1414
import importlib.machinery # importlib first so we can test #15386 via -m
1515
import importlib.util
16+
import io
1617
import types
1718
from pkgutil import read_code, get_importer
1819

@@ -228,11 +229,11 @@ def _get_main_module_details(error=ImportError):
228229

229230
def _get_code_from_file(run_name, fname):
230231
# Check for a compiled file first
231-
with open(fname, "rb") as f:
232+
with io.open_code(fname) as f:
232233
code = read_code(f)
233234
if code is None:
234235
# That didn't work, so try it as normal source code
235-
with open(fname, "rb") as f:
236+
with io.open_code(fname) as f:
236237
code = compile(f.read(), fname, 'exec')
237238
return code, fname
238239

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`runpy` now uses :meth:`io.open_code` to open code files.
2+
Patch by Jason Killen.

0 commit comments

Comments
 (0)