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

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
This commit is contained in:
Steve Dower 2023-05-22 11:40:30 +01:00 committed by GitHub
parent 98016f7c92
commit d1645ce4f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 3 deletions

View file

@ -49,6 +49,7 @@
"""
__all__ = ['Trace', 'CoverageResults']
import io
import linecache
import os
import sys
@ -716,7 +717,7 @@ def parse_ignore_dir(s):
sys.argv = [opts.progname, *opts.arguments]
sys.path[0] = os.path.dirname(opts.progname)
with open(opts.progname, 'rb') as fp:
with io.open_code(opts.progname) as fp:
code = compile(fp.read(), opts.progname, 'exec')
# try to emulate __main__ namespace as much as possible
globs = {