Skip to content

Commit 4e4c0bb

Browse files
committed
Don't let help formatter line-wrap URLs (#19816)
1 parent 9ae3e9a commit 4e4c0bb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

mypy/main.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,14 @@ def _fill_text(self, text: str, width: int, indent: str) -> str:
256256
if "\n" in text:
257257
# Assume we want to manually format the text
258258
return super()._fill_text(text, width, indent)
259-
else:
260-
# Assume we want argparse to manage wrapping, indenting, and
261-
# formatting the text for us.
262-
return argparse.HelpFormatter._fill_text(self, text, width, indent)
259+
# Format the text like argparse, but overflow rather than
260+
# breaking long words (like URLs)
261+
text = self._whitespace_matcher.sub(' ', text).strip()
262+
import textwrap
263+
return textwrap.fill(
264+
text, width,
265+
initial_indent=indent, subsequent_indent=indent,
266+
break_on_hyphens=False, break_long_words=False)
263267

264268

265269
# Define pairs of flag prefixes with inverse meaning.

0 commit comments

Comments
 (0)