From 4e4c0bb5712dc2ca402db8fd2b23483f15fce4f1 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Thu, 11 Sep 2025 02:49:57 -0400 Subject: [PATCH 1/4] Don't let help formatter line-wrap URLs (#19816) --- mypy/main.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index d5bbca704305..ee38db161603 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -256,10 +256,14 @@ def _fill_text(self, text: str, width: int, indent: str) -> str: if "\n" in text: # Assume we want to manually format the text return super()._fill_text(text, width, indent) - else: - # Assume we want argparse to manage wrapping, indenting, and - # formatting the text for us. - return argparse.HelpFormatter._fill_text(self, text, width, indent) + # Format the text like argparse, but overflow rather than + # breaking long words (like URLs) + text = self._whitespace_matcher.sub(' ', text).strip() + import textwrap + return textwrap.fill( + text, width, + initial_indent=indent, subsequent_indent=indent, + break_on_hyphens=False, break_long_words=False) # Define pairs of flag prefixes with inverse meaning. From e09361b22c40b5baf15199834ad6b906692d2d1c Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Thu, 11 Sep 2025 02:50:46 -0400 Subject: [PATCH 2/4] Add https:// before two URLs in cmdline help (#19816) They won't be recognized as links without it. --- mypy/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index ee38db161603..c71fbcfb89fa 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -1038,7 +1038,7 @@ def add_invertible_flag( "Mypy caches type information about modules into a cache to " "let you speed up future invocations of mypy. Also see " "mypy's daemon mode: " - "mypy.readthedocs.io/en/stable/mypy_daemon.html#mypy-daemon", + "https://mypy.readthedocs.io/en/stable/mypy_daemon.html#mypy-daemon", ) incremental_group.add_argument( "-i", "--incremental", action="store_true", help=argparse.SUPPRESS @@ -1289,7 +1289,7 @@ def add_invertible_flag( code_group = parser.add_argument_group( title="Running code", description="Specify the code you want to type check. For more details, see " - "mypy.readthedocs.io/en/stable/running_mypy.html#running-mypy", + "https://mypy.readthedocs.io/en/stable/running_mypy.html#running-mypy", ) add_invertible_flag( "--explicit-package-bases", From b660c43bb0f9e74bc8efd78a256c0bbe0347f052 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 11 Sep 2025 07:03:07 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypy/main.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index c71fbcfb89fa..052a1bab69d2 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -258,12 +258,17 @@ def _fill_text(self, text: str, width: int, indent: str) -> str: return super()._fill_text(text, width, indent) # Format the text like argparse, but overflow rather than # breaking long words (like URLs) - text = self._whitespace_matcher.sub(' ', text).strip() + text = self._whitespace_matcher.sub(" ", text).strip() import textwrap + return textwrap.fill( - text, width, - initial_indent=indent, subsequent_indent=indent, - break_on_hyphens=False, break_long_words=False) + text, + width, + initial_indent=indent, + subsequent_indent=indent, + break_on_hyphens=False, + break_long_words=False, + ) # Define pairs of flag prefixes with inverse meaning. From 0d60f10425cc10316eb0e944b2dac2f0bda33f12 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Thu, 11 Sep 2025 14:45:21 -0400 Subject: [PATCH 4/4] Update 'mypy --help' style guide Now that URLs in help text are output to the terminal unbroken, so length isn't an issue, we should always include the `https://` scheme identifier to facilitate autodetection. Not following with a period is still good advice, to facilitate manual copy-pasting. --- mypy/main.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index 052a1bab69d2..b288f81c83d4 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -553,10 +553,15 @@ def add_invertible_flag( # Feel free to add subsequent sentences that add additional details. # 3. If you cannot think of a meaningful description for a new group, omit it entirely. # (E.g. see the "miscellaneous" sections). - # 4. The group description should end with a period (unless the last line is a link). If you - # do end the group description with a link, omit the 'http://' prefix. (Some links are too - # long and will break up into multiple lines if we include that prefix, so for consistency - # we omit the prefix on all links.) + # 4. The text of the group description should end with a period, optionally followed + # by a documentation reference (URL). + # 5. If you want to include a documentation reference, place it at the end of the + # description. Feel free to open with a brief reference ("See also:", "For more + # information:", etc.), followed by a space, then the entire URL including + # "https://" scheme identifier and fragment ("#some-target-heading"), if any. + # Do not end with a period (or any other characters not part of the URL). + # URLs longer than the available terminal width will overflow without being + # broken apart. This facilitates both URL detection, and manual copy-pasting. general_group = parser.add_argument_group(title="Optional arguments") general_group.add_argument(