gh-103935: Use io.open_code() when executing code in trace and profile modules (GH-103947)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
This commit is contained in:
Steve Dower 2023-04-27 22:23:46 +01:00 committed by GitHub
parent dbc44fab7a
commit 57d198ec83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 3 deletions

View file

@ -7,6 +7,7 @@
__all__ = ["run", "runctx", "Profile"]
import _lsprof
import io
import profile as _pyprofile
# ____________________________________________________________
@ -167,7 +168,7 @@ def main():
else:
progname = args[0]
sys.path.insert(0, os.path.dirname(progname))
with open(progname, 'rb') as fp:
with io.open_code(progname) as fp:
code = compile(fp.read(), progname, 'exec')
globs = {
'__file__': progname,