Skip to content

Commit 72f1e5c

Browse files
blacken
1 parent c76183d commit 72f1e5c

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed

mypy/main.py

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -369,33 +369,45 @@ def infer_python_executable(options: Options, special_opts: argparse.Namespace)
369369
Define MYPYPATH for additional module search path entries.
370370
Define MYPY_CACHE_DIR to override configuration cache_dir path."""
371371

372+
372373
def is_terminal_punctuation(char: str) -> bool:
373374
return char in (".", "?", "!")
374375

376+
375377
class ArgumentGroup:
376378
"""A wrapper for argparse's ArgumentGroup class that lets us enforce capitalization
377379
on the added arguments."""
380+
378381
def __init__(self, argument_group: argparse._ArgumentGroup) -> None:
379382
self.argument_group = argument_group
380383

381-
def add_argument(self, *name_or_flags, help=None, **kwargs) -> argparse.Action:
384+
def add_argument(self, *name_or_flags, help=None, **kwargs) -> argparse.Action:
382385
if self.argument_group.title == "Report generation":
383386
if help and help != argparse.SUPPRESS:
384-
raise ValueError(f"CLI documentation style error: help description for the Report generation flag {name_or_flags} was unexpectedly provided. (Currently, '{help}'.)"
387+
raise ValueError(
388+
f"CLI documentation style error: help description for the Report generation flag {name_or_flags} was unexpectedly provided. (Currently, '{help}'.)"
385389
+ " This check is in the code because we assume there's nothing help to say about the report flags."
386390
+ " If you're improving that situation, feel free to remove this check."
387391
)
388392
else:
389393
if not help:
390-
raise ValueError(f"CLI documentation style error: flag help description for {name_or_flags} must be provided. (Currently, '{help}'.)")
394+
raise ValueError(
395+
f"CLI documentation style error: flag help description for {name_or_flags} must be provided. (Currently, '{help}'.)"
396+
)
391397
if help[0] != help[0].upper():
392-
raise ValueError(f"CLI documentation style error: flag help description for {name_or_flags} must start with a capital letter (or unicameral symbol). (Currently, '{help}'.)")
393-
if help[-1] == '.':
394-
raise ValueError(f"CLI documentation style error: flag help description for {name_or_flags} must NOT end with a period. (Currently, '{help}'.)")
398+
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}'.)"
400+
)
401+
if help[-1] == ".":
402+
raise ValueError(
403+
f"CLI documentation style error: flag help description for {name_or_flags} must NOT end with a period. (Currently, '{help}'.)"
404+
)
395405
return self.argument_group.add_argument(*name_or_flags, help=help, **kwargs)
396-
406+
397407
def _add_action(self, action) -> None:
398408
self.argument_group._add_action(action)
409+
410+
399411
class CapturableArgumentParser(argparse.ArgumentParser):
400412
"""Override ArgumentParser methods that use sys.stdout/sys.stderr directly.
401413
@@ -415,20 +427,28 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
415427
# =====================
416428
# We just hard fail on these, as CI will ensure the runtime errors never get to users.
417429
def add_argument_group(
418-
self,
419-
title: str,
420-
description: str | None = None,
421-
**kwargs,
430+
self, title: str, description: str | None = None, **kwargs
422431
) -> ArgumentGroup:
423-
if title not in ["positional arguments", "options"]: # These are built-in names, ignore them.
432+
if title not in [
433+
"positional arguments",
434+
"options",
435+
]: # These are built-in names, ignore them.
424436
if not title[0].isupper():
425-
raise ValueError(f"CLI documentation style error: Title of group {title} must start with a capital letter. (Currently, '{title[0]}'.)")
437+
raise ValueError(
438+
f"CLI documentation style error: Title of group {title} must start with a capital letter. (Currently, '{title[0]}'.)"
439+
)
426440
if description and not description[0].isupper():
427-
raise ValueError(f"CLI documentation style error: Description of group {title} must start with a capital letter. (Currently, '{description[0]}'.)")
441+
raise ValueError(
442+
f"CLI documentation style error: Description of group {title} must start with a capital letter. (Currently, '{description[0]}'.)"
443+
)
428444
if is_terminal_punctuation(title[-1]):
429-
raise ValueError(f"CLI documentation style error: Title of group {title} must NOT end with terminal punction. (Currently, '{title[-1]}'.)")
445+
raise ValueError(
446+
f"CLI documentation style error: Title of group {title} must NOT end with terminal punction. (Currently, '{title[-1]}'.)"
447+
)
430448
if description and not is_terminal_punctuation(description[-1]):
431-
raise ValueError(f"CLI documentation style error: Description of group {title} must end with terminal punction. (Currently, '{description[-1]}'.)")
449+
raise ValueError(
450+
f"CLI documentation style error: Description of group {title} must end with terminal punction. (Currently, '{description[-1]}'.)"
451+
)
432452
return ArgumentGroup(super().add_argument_group(title, description, **kwargs))
433453

434454
# =====================
@@ -1148,9 +1168,10 @@ def add_invertible_flag(
11481168
"--new-type-inference", action="store_true", help=argparse.SUPPRESS
11491169
)
11501170
experimental_group = parser.add_argument_group(
1151-
title="Experimental options", description="Enable features that work well enough to be useful,"
1171+
title="Experimental options",
1172+
description="Enable features that work well enough to be useful,"
11521173
+ " but perhaps not as well as you might wish."
1153-
+ " These features may be enabled by default in the future, or perhaps moved to another section."
1174+
+ " These features may be enabled by default in the future, or perhaps moved to another section.",
11541175
)
11551176
experimental_group.add_argument(
11561177
"--enable-incomplete-feature",

0 commit comments

Comments
 (0)