summaryrefslogtreecommitdiffstats
path: root/Lib/profile.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2022-10-06 22:40:22 (GMT)
committerGitHub <noreply@github.com>2022-10-06 22:40:22 (GMT)
commite1c4d56fdde28728c37de855edbb463fa0d7f95d (patch)
treeb4c3a715e975f6349a8b07d856965fffb911f26d /Lib/profile.py
parentf8edc6ff531bb98858185857513371f14519ed1d (diff)
downloadcpython-e1c4d56fdde28728c37de855edbb463fa0d7f95d.zip
cpython-e1c4d56fdde28728c37de855edbb463fa0d7f95d.tar.gz
cpython-e1c4d56fdde28728c37de855edbb463fa0d7f95d.tar.bz2
gh-65961: Do not rely solely on `__cached__` (GH-97990)
Make sure `__spec__.cached` (at minimum) can be used.
Diffstat (limited to 'Lib/profile.py')
-rwxr-xr-xLib/profile.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/profile.py b/Lib/profile.py
index d8599fb..453e562 100755
--- a/Lib/profile.py
+++ b/Lib/profile.py
@@ -24,6 +24,7 @@
# governing permissions and limitations under the License.
+import importlib.machinery
import sys
import time
import marshal
@@ -589,9 +590,12 @@ def main():
sys.path.insert(0, os.path.dirname(progname))
with open(progname, 'rb') as fp:
code = compile(fp.read(), progname, 'exec')
+ spec = importlib.machinery.ModuleSpec(name='__main__', loader=None,
+ origin=progname)
globs = {
- '__file__': progname,
- '__name__': '__main__',
+ '__spec__': spec,
+ '__file__': spec.origin,
+ '__name__': spec.name,
'__package__': None,
'__cached__': None,
}