]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-140228: Avoid making unnecessary syscalls in linecache for frozen modules...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 29 Oct 2025 16:26:38 +0000 (17:26 +0100)
committerGitHub <noreply@github.com>
Wed, 29 Oct 2025 16:26:38 +0000 (09:26 -0700)
gh-140228: Avoid making unnecessary syscalls in linecache for frozen modules (GH-140377)
(cherry picked from commit c41f84ff61c52e3ff7ef86b0c66208b29613d23d)

Co-authored-by: tconley1428 <tconley1428@gmail.com>
Lib/linecache.py
Misc/NEWS.d/next/Library/2025-10-28-17-43-51.gh-issue-140228.8kfHhO.rst [new file with mode: 0644]

index 87d7d6fda657e474f6e258a391df9199fe974c91..2b5a31b3e75bc1a988c8502e84736459f00bb960 100644 (file)
@@ -131,9 +131,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 (file)
index 0000000..b3b692b
--- /dev/null
@@ -0,0 +1 @@
+Avoid making unnecessary filesystem calls for frozen modules in :mod:`linecache` when the global module cache is not present.