Skip to content

Commit c41f84f

Browse files
authored
gh-140228: Avoid making unnecessary syscalls in linecache for frozen modules (#140377)
1 parent ce4b0ed commit c41f84f

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Lib/linecache.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,12 @@ def updatecache(filename, module_globals=None):
123123
if _source_unavailable(filename):
124124
return []
125125

126-
if filename.startswith('<frozen ') and module_globals is not None:
126+
if filename.startswith('<frozen '):
127127
# This is a frozen module, so we need to use the filename
128128
# from the module globals.
129+
if module_globals is None:
130+
return []
131+
129132
fullname = module_globals.get('__file__')
130133
if fullname is None:
131134
return []
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Avoid making unnecessary filesystem calls for frozen modules in :mod:`linecache` when the global module cache is not present.

0 commit comments

Comments
 (0)