Skip to content

Commit 2c45a29

Browse files
improve cli formatting error message and also linewrapping
1 parent 31dc2ff commit 2c45a29

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

mypy/main.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -384,23 +384,27 @@ def __init__(self, argument_group: argparse._ArgumentGroup) -> None:
384384
def add_argument(self, *name_or_flags, help=None, **kwargs) -> argparse.Action:
385385
if self.argument_group.title == "Report generation":
386386
if help and help != argparse.SUPPRESS:
387-
raise ValueError(
388-
f"CLI documentation style error: help description for the Report generation flag {name_or_flags} was unexpectedly provided. (Currently, '{help}'.)"
389-
+ " This check is in the code because we assume there's nothing help to say about the report flags."
390-
+ " If you're improving that situation, feel free to remove this check."
387+
ValueError(
388+
"Mypy-internal CLI documentation style error: help description for the Report generation flag"
389+
+ f" {name_or_flags} was unexpectedly provided. (Currently, '{help}'.)"
390+
+ " This check is in the code because we assume there's nothing help to say about the report flags."
391+
+ " If you're improving that situation, feel free to remove this check."
391392
)
392393
else:
393394
if not help:
394395
raise ValueError(
395-
f"CLI documentation style error: flag help description for {name_or_flags} must be provided. (Currently, '{help}'.)"
396+
f"Mypy-internal CLI documentation style error: flag help description for {name_or_flags}"
397+
+ f" must be provided. (Currently, '{help}'.)"
396398
)
397399
if help[0] != help[0].upper():
398400
raise ValueError(
399-
f"CLI documentation style error: flag help description for {name_or_flags} must start with a capital letter (or unicameral symbol). (Currently, '{help}'.)"
401+
f"Mypy-internal CLI documentation style error: flag help description for {name_or_flags}"
402+
+ f" must start with a capital letter (or unicameral symbol). (Currently, '{help}'.)"
400403
)
401404
if help[-1] == ".":
402405
raise ValueError(
403-
f"CLI documentation style error: flag help description for {name_or_flags} must NOT end with a period. (Currently, '{help}'.)"
406+
f"Mypy-internal CLI documentation style error: flag help description for {name_or_flags}"
407+
+ f" must NOT end with a period. (Currently, '{help}'.)"
404408
)
405409
return self.argument_group.add_argument(*name_or_flags, help=help, **kwargs)
406410

@@ -435,19 +439,23 @@ def add_argument_group(
435439
]: # These are built-in names, ignore them.
436440
if not title[0].isupper():
437441
raise ValueError(
438-
f"CLI documentation style error: Title of group {title} must start with a capital letter. (Currently, '{title[0]}'.)"
442+
f"CLI documentation style error: Title of group {title}"
443+
+ f" must start with a capital letter. (Currently, '{title[0]}'.)"
439444
)
440445
if description and not description[0].isupper():
441446
raise ValueError(
442-
f"CLI documentation style error: Description of group {title} must start with a capital letter. (Currently, '{description[0]}'.)"
447+
f"CLI documentation style error: Description of group {title}"
448+
+ f" must start with a capital letter. (Currently, '{description[0]}'.)"
443449
)
444450
if is_terminal_punctuation(title[-1]):
445451
raise ValueError(
446-
f"CLI documentation style error: Title of group {title} must NOT end with terminal punction. (Currently, '{title[-1]}'.)"
452+
f"CLI documentation style error: Title of group {title}"
453+
+ f" must NOT end with terminal punction. (Currently, '{title[-1]}'.)"
447454
)
448455
if description and not is_terminal_punctuation(description[-1]):
449456
raise ValueError(
450-
f"CLI documentation style error: Description of group {title} must end with terminal punction. (Currently, '{description[-1]}'.)"
457+
f"CLI documentation style error: Description of group {title}"
458+
+ f" must end with terminal punction. (Currently, '{description[-1]}'.)"
451459
)
452460
return ArgumentGroup(super().add_argument_group(title, description, **kwargs))
453461

@@ -538,7 +546,8 @@ def define_options(
538546
stderr: TextIO = sys.stderr,
539547
server_options: bool = False,
540548
) -> tuple[CapturableArgumentParser, list[str], list[tuple[str, bool]]]:
541-
"""Define the options in the parser (by calling a bunch of methods that express/build our desired command-line flags).
549+
"""Define the options in the parser
550+
(by calling a bunch of methods that express/build our desired command-line flags).
542551
Returns a tuple of:
543552
a parser object, that can parse command line arguments to mypy (expected consumer: main's process_options),
544553
a list of what flags are strict (expected consumer: docs' html_builder's _add_strict_list),
@@ -638,7 +647,8 @@ def add_invertible_flag(
638647
"-O",
639648
"--output",
640649
metavar="FORMAT",
641-
# The metavar overrides the default of displaying the choices, so we have to explicitly display them.
650+
# The metavar overrides the default of displaying the choices,
651+
# so we have to explicitly display them.
642652
help=f"Set a custom output format (choices: {set(OUTPUT_CHOICES.keys())})",
643653
choices=OUTPUT_CHOICES,
644654
)
@@ -1167,7 +1177,8 @@ def add_invertible_flag(
11671177
title="Experimental options",
11681178
description="Enable features that work well enough to be useful,"
11691179
+ " but perhaps not as well as you might wish."
1170-
+ " These features may be enabled by default in the future, or perhaps moved to another section.",
1180+
+ " These features may be enabled by default in the future,"
1181+
+ " or perhaps moved to another section.",
11711182
)
11721183
experimental_group.add_argument(
11731184
"--enable-incomplete-feature",
@@ -1240,7 +1251,9 @@ def add_invertible_flag(
12401251
"--junit-format",
12411252
choices=["global", "per_file"],
12421253
default="global",
1243-
help="If --junit-xml is set, specifies format. global: single test with all errors; per_file: one test entry per file with failures",
1254+
help="If --junit-xml is set, specifies format."
1255+
+ " global: single test with all errors;"
1256+
+ " per_file: one test entry per file with failures",
12441257
)
12451258
misc_group.add_argument(
12461259
"--scripts-are-modules",
@@ -1596,7 +1609,8 @@ def set_strict_flags() -> None:
15961609
reason = cache.find_module(p)
15971610
if reason is ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS:
15981611
fail(
1599-
f"Package '{p}' cannot be type checked due to missing py.typed marker. See https://mypy.readthedocs.io/en/stable/installed_packages.html for more details",
1612+
f"Package '{p}' cannot be type checked due to missing py.typed marker."
1613+
+ " See https://mypy.readthedocs.io/en/stable/installed_packages.html for more details",
16001614
stderr,
16011615
options,
16021616
)

0 commit comments

Comments
 (0)