FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-117865: Defer import of re in ast by JelleZijlstra · Pull Request #119546 · python/cpython · GitHub

/ cpython Public

gh-117865: Defer import of re in ast - #119546

Merged
JelleZijlstra merged 2 commits into
python:mainfrom
JelleZijlstra:ast-re
May 28, 2024
Merged

gh-117865: Defer import of re in ast#119546
JelleZijlstra merged 2 commits into
python:mainfrom
JelleZijlstra:ast-re

Conversation

JelleZijlstra commented May 25, 2024
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

This is used only by ast.get_source_segment(), so it seems sensible to avoid importing it.

Copy link
Copy Markdown
Member

How much does this speedup the import of inspect? I wouldn't expect it to do much on its own, since inspect itself also imports re. Or is the idea that this could be done in combination with some of the changes in #119526?

Copy link
Copy Markdown
Member

(Though it's probably worth doing even if it just speeds up the import of ast. I guess I was looking at it through the lens of the github issue it was attached to.)

AlexWaygood left a comment

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Locally for me this cuts about 20% off the import time for ast (0.0036s -> 0.0029s), so this seems worth doing. This is especially true since the _splitlines_no_ff function is only ever used in get_source_segment, which is one of the lesser-used ast-module APIs

Comment thread Lib/ast.py
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
JelleZijlstra merged commit ae11d68 into python:main May 28, 2024
JelleZijlstra deleted the ast-re branch May 28, 2024 18:04
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
This is used only by ast.get_source_segment(), so it seems sensible to avoid importing it.

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL