Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd50f01a

Browse files
gh-103935: Useio.open_code() when executing code in trace and profile modules (GH-103947)
1 parentbf0b8a9 commitd50f01a

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

‎Lib/cProfile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import_lsprof
1010
importimportlib.machinery
11+
importio
1112
importprofileas_pyprofile
1213

1314
# ____________________________________________________________
@@ -168,7 +169,7 @@ def main():
168169
else:
169170
progname=args[0]
170171
sys.path.insert(0,os.path.dirname(progname))
171-
withopen(progname,'rb')asfp:
172+
withio.open_code(progname)asfp:
172173
code=compile(fp.read(),progname,'exec')
173174
spec=importlib.machinery.ModuleSpec(name='__main__',loader=None,
174175
origin=progname)

‎Lib/profile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626

2727
importimportlib.machinery
28+
importio
2829
importsys
2930
importtime
3031
importmarshal
@@ -588,7 +589,7 @@ def main():
588589
else:
589590
progname=args[0]
590591
sys.path.insert(0,os.path.dirname(progname))
591-
withopen(progname,'rb')asfp:
592+
withio.open_code(progname)asfp:
592593
code=compile(fp.read(),progname,'exec')
593594
spec=importlib.machinery.ModuleSpec(name='__main__',loader=None,
594595
origin=progname)

‎Lib/trace.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"""
5050
__all__= ['Trace','CoverageResults']
5151

52+
importio
5253
importlinecache
5354
importos
5455
importsys
@@ -716,7 +717,7 @@ def parse_ignore_dir(s):
716717
sys.argv= [opts.progname,*opts.arguments]
717718
sys.path[0]=os.path.dirname(opts.progname)
718719

719-
withopen(opts.progname,'rb')asfp:
720+
withio.open_code(opts.progname)asfp:
720721
code=compile(fp.read(),opts.progname,'exec')
721722
# try to emulate __main__ namespace as much as possible
722723
globs= {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use:func:`io.open_code` for files to be executed instead of raw:func:`open`

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp