{{ message }}
gh-118761: improve optparse import time by delaying textwrap import - #128899
Merged
Merged
Conversation
1 task
ZeroIntensity
approved these changes
Jan 16, 2025
AA-Turner
reviewed
Jan 16, 2025
Comment on lines
+254
to
+256
Member
There was a problem hiding this comment.
Style: move local imports to the top of the block
Suggested change
| text_width = max(self.width - self.current_indent, 11) | |
| indent = " "*self.current_indent | |
| import textwrap | |
| import textwrap | |
| text_width = max(self.width - self.current_indent, 11) | |
| indent = " "*self.current_indent |
Contributor
Author
There was a problem hiding this comment.
Sure, makes sense!
For what it's worth the reason I did it this way was a direct consequence of having just been reading argparse.py, which breaks this style suggestion, while documenting the motivation of the change. :) I suppose it is not worth bothering with the churn there as it's just a style nit on code that isn't being modified already...
| help_text = self.expand_default(option) | ||
| import textwrap |
Member
There was a problem hiding this comment.
Style: move local imports to the top of the block
Suggested change
| help_text = self.expand_default(option) | |
| import textwrap | |
| import textwrap | |
| help_text = self.expand_default(option) |
…port The same change was made, and for the same reason, by argparse back in 2017. The textwrap module is only used when printing help text, so most invocations will never need it imported. See: python#1269 See: 8110837
eli-schwartz
force-pushed
the
optparse-importtime
branch
from
January 17, 2025 00:44
4484efc to
10cd152
Compare
Member
|
Out of curiosity, how are the |
Contributor
Author
AA-Turner
approved these changes
Jan 20, 2025
srinivasreddy
pushed a commit
to srinivasreddy/cpython
that referenced
this pull request
Jan 21, 2025
The same change was made, and for the same reason, by ``argparse`` back in 2017. The ``textwrap`` module is only used when printing help text, so most invocations will never need it imported. Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The same change was made, and for the same reason, by argparse back in
2017. The textwrap module is only used when printing help text, so most invocations will never need it imported.
See: #1269
See: 8110837