Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Lib/linecache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
that name.
"""

import sys
import os

__all__ = ["getline", "clearcache", "checkcache", "lazycache"]


Expand Down Expand Up @@ -66,6 +63,11 @@ def checkcache(filename=None):
size, mtime, lines, fullname = entry
if mtime is None:
continue # no-op for files loaded via a __loader__
try:
# This import can fail if the interpreter is shutting down
import os
except ImportError:
return
try:
stat = os.stat(fullname)
except OSError:
Expand All @@ -76,6 +78,12 @@ def checkcache(filename=None):


def updatecache(filename, module_globals=None):
# These imports are not at top level because linecache is in the critical
# path of the interpreter startup and importing os and sys take a lot of time
# and slow down the startup sequence.
import os
import sys

"""Update a cache entry and return its list of lines.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We lost the docstring because you put the imports before it. Filed #117948 to fix this.

If something's wrong, print a message, discard the cache entry,
and return an empty list."""
Expand Down