Defer import of shutil which only needed for help and usage (GH-17334)
https://github.com/python/cpython/commit/b4e5eeac267c436bb60776dc5be771d3259... commit: b4e5eeac267c436bb60776dc5be771d3259bd298 branch: master author: Raymond Hettinger <rhettinger@users.noreply.github.com> committer: GitHub <noreply@github.com> date: 2019-11-21T22:51:45-08:00 summary: Defer import of shutil which only needed for help and usage (GH-17334) files: M Lib/argparse.py diff --git a/Lib/argparse.py b/Lib/argparse.py index 5a8eff2f4cc89..5d3ce2ad709f0 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -87,7 +87,6 @@ import os as _os import re as _re -import shutil as _shutil import sys as _sys from gettext import gettext as _, ngettext @@ -167,7 +166,8 @@ def __init__(self, # default setting for width if width is None: - width = _shutil.get_terminal_size().columns + import shutil + width = shutil.get_terminal_size().columns width -= 2 self._prog = prog @@ -264,7 +264,7 @@ def add_argument(self, action): invocations.append(get_invocation(subaction)) # update the maximum item length - invocation_length = max([len(s) for s in invocations]) + invocation_length = max(map(len, invocations)) action_length = invocation_length + self._current_indent self._action_max_length = max(self._action_max_length, action_length)
participants (1)
-
Raymond Hettinger