]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-140228: Avoid making unnecessary syscalls in linecache for frozen modules (#140377)
authortconley1428 <tconley1428@gmail.com>
Wed, 29 Oct 2025 06:06:22 +0000 (23:06 -0700)
committerGitHub <noreply@github.com>
Wed, 29 Oct 2025 06:06:22 +0000 (23:06 -0700)
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 ef73d1aa99774a8825c6beba73fef848318ecefb..ef3b2d9136b4d20fc0175af7fdd359884c66a6a9 100644 (file)
@@ -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 (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.