Skip to content

gh-67224: Make linecache imports relative to improve startup speed#117501

Merged
pablogsal merged 2 commits intopython:mainfrom
pablogsal:gh-67224-2
Apr 10, 2024
Merged

gh-67224: Make linecache imports relative to improve startup speed#117501
pablogsal merged 2 commits intopython:mainfrom
pablogsal:gh-67224-2

Conversation

@pablogsal
Copy link
Copy Markdown
Member

@pablogsal pablogsal commented Apr 3, 2024

Comment thread Lib/linecache.py Outdated
@pablogsal
Copy link
Copy Markdown
Member Author

Oh man, seems this is complicated because making the import lazy actually fails at shutdown because if the first time this is called its when the interpreter is shutting down, sys.meta_path is None :(

@pablogsal
Copy link
Copy Markdown
Member Author

Well, I think this should do the trick

Comment thread Lib/linecache.py Outdated
Comment thread Lib/linecache.py
Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM. Just a suggestion to reorganize checkcache() import/except ImportError.

Comment thread Lib/linecache.py
Comment thread Lib/linecache.py Outdated
@pablogsal pablogsal merged commit 689ada7 into python:main Apr 10, 2024
@pablogsal pablogsal deleted the gh-67224-2 branch April 10, 2024 19:09
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this pull request Apr 16, 2024
pythongh-117501 put some code before the docstring, so now it is no longer
recognized as a docstring.
Comment thread Lib/linecache.py
import os
import sys

"""Update a cache entry and return its list of lines.
Copy link
Copy Markdown
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.

hauntsaninja pushed a commit that referenced this pull request Apr 16, 2024
gh-117501 put some code before the docstring, so now it is no longer
recognized as a docstring.
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
pythongh-117501 put some code before the docstring, so now it is no longer
recognized as a docstring.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants