summaryrefslogtreecommitdiff
path: root/Lib/cProfile.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2022-10-06 15:40:22 -0700
committerGitHub <noreply@github.com>2022-10-06 15:40:22 -0700
commite1c4d56fdde28728c37de855edbb463fa0d7f95d (patch)
treeb4c3a715e975f6349a8b07d856965fffb911f26d /Lib/cProfile.py
parentf8edc6ff531bb98858185857513371f14519ed1d (diff)
downloadcpython-git-e1c4d56fdde28728c37de855edbb463fa0d7f95d.tar.gz
gh-65961: Do not rely solely on `__cached__` (GH-97990)
Make sure `__spec__.cached` (at minimum) can be used.
Diffstat (limited to 'Lib/cProfile.py')
-rwxr-xr-xLib/cProfile.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/cProfile.py b/Lib/cProfile.py
index 9fc9788302..f7000a8bfa 100755
--- a/Lib/cProfile.py
+++ b/Lib/cProfile.py
@@ -7,6 +7,7 @@
__all__ = ["run", "runctx", "Profile"]
import _lsprof
+import importlib.machinery
import profile as _pyprofile
# ____________________________________________________________
@@ -169,9 +170,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,
}