https://github.com/python/cpython/commit/c41f84ff61c52e3ff7ef86b0c66208b29613d23d
commit: c41f84ff61c52e3ff7ef86b0c66208b29613d23d
branch: main
author: tconley1428 <[email protected]>
committer: gaogaotiantian <[email protected]>
date: 2025-10-28T23:06:22-07:00
summary:
gh-140228: Avoid making unnecessary syscalls in linecache for frozen modules
(#140377)
files:
A Misc/NEWS.d/next/Library/2025-10-28-17-43-51.gh-issue-140228.8kfHhO.rst
M Lib/linecache.py
diff --git a/Lib/linecache.py b/Lib/linecache.py
index ef73d1aa99774a..ef3b2d9136b4d2 100644
--- a/Lib/linecache.py
+++ b/Lib/linecache.py
@@ -123,9 +123,12 @@ def updatecache(filename, module_globals=None):
if _source_unavailable(filename):
return []
- if filename.startswith('<frozen ') and module_globals is not None:
+ if filename.startswith('<frozen '):
# This is a frozen module, so we need to use the filename
# from the module globals.
+ if module_globals is None:
+ return []
+
fullname = module_globals.get('__file__')
if fullname is None:
return []
diff --git
a/Misc/NEWS.d/next/Library/2025-10-28-17-43-51.gh-issue-140228.8kfHhO.rst
b/Misc/NEWS.d/next/Library/2025-10-28-17-43-51.gh-issue-140228.8kfHhO.rst
new file mode 100644
index 00000000000000..b3b692bae62c5d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-10-28-17-43-51.gh-issue-140228.8kfHhO.rst
@@ -0,0 +1 @@
+Avoid making unnecessary filesystem calls for frozen modules in
:mod:`linecache` when the global module cache is not present.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]