diff --git a/Lib/optparse.py b/Lib/optparse.py index cbe3451ced8bc37..96117a0f2205f47 100644 --- a/Lib/optparse.py +++ b/Lib/optparse.py @@ -74,7 +74,6 @@ """ import sys, os -import textwrap from gettext import gettext as _, ngettext @@ -254,6 +253,7 @@ def _format_text(self, text): """ text_width = max(self.width - self.current_indent, 11) indent = " "*self.current_indent + import textwrap return textwrap.fill(text, text_width, initial_indent=indent, @@ -309,6 +309,7 @@ def format_option(self, option): result.append(opts) if option.help: help_text = self.expand_default(option) + import textwrap help_lines = textwrap.wrap(help_text, self.help_width) result.append("%*s%s\n" % (indent_first, "", help_lines[0])) result.extend(["%*s%s\n" % (self.help_position, "", line) diff --git a/Misc/NEWS.d/next/Library/2025-01-15-18-54-48.gh-issue-118761.G1dv6E.rst b/Misc/NEWS.d/next/Library/2025-01-15-18-54-48.gh-issue-118761.G1dv6E.rst new file mode 100644 index 000000000000000..4144ef8f40e6dd6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-01-15-18-54-48.gh-issue-118761.G1dv6E.rst @@ -0,0 +1,2 @@ +Reduce the import time of :mod:`optparse` when no help text is printed. +Patch by Eli Schwartz.