Skip to content

Conversation

@JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented May 25, 2024

This is used only by ast.get_source_segment(), so it seems sensible to avoid importing it.
@AlexWaygood
Copy link
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?

@AlexWaygood
Copy link
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.)

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

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

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@JelleZijlstra JelleZijlstra merged commit ae11d68 into python:main May 28, 2024
@JelleZijlstra 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>
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