Skip to content

Commit d65834f

Browse files
committed
Adjust output of --help text to mirror command line changes
This commit adjusts the output of running `mypy --help` to mirror the changes made in python#5333. Specifically, it rearranges the order of the flags slightly and replaces the summary of the flags at the top with a short description of how to use mypy along with links for learning more.
1 parent 219fbf8 commit d65834f

File tree

1 file changed

+58
-24
lines changed

1 file changed

+58
-24
lines changed

mypy/main.py

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ def type_check_only(sources: List[BuildSource], bin_dir: Optional[str],
148148
fscache=fscache)
149149

150150

151-
FOOTER = "environment variables: Define MYPYPATH for additional module search path entries."
152-
153-
154151
class SplitNamespace(argparse.Namespace):
155152
def __init__(self, standard_namespace: object, alt_namespace: object, alt_prefix: str) -> None:
156153
self.__dict__['_standard_namespace'] = standard_namespace
@@ -195,7 +192,7 @@ def parse_version(v: str) -> Tuple[int, int]:
195192

196193

197194
# Make the help output a little less jarring.
198-
class AugmentedHelpFormatter(argparse.HelpFormatter):
195+
class AugmentedHelpFormatter(argparse.RawDescriptionHelpFormatter):
199196
def __init__(self, prog: str) -> None:
200197
super().__init__(prog=prog, max_help_position=28)
201198

@@ -297,6 +294,37 @@ def infer_python_version_and_executable(options: Options,
297294
options.python_executable = special_opts.python_executable
298295

299296

297+
HEADER = """%(prog)s [-h] [-v] [-V] [more options; see below]
298+
[-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files [files ...]]"""
299+
300+
301+
DESCRIPTION = """
302+
Mypy is a program that will type check your Python code.
303+
304+
Pass in any files or folders you want to type check. Mypy will
305+
recursively traverse any provided folders to find .py files:
306+
307+
$ mypy my_program.py my_src_folder
308+
309+
For more information on getting started, see:
310+
311+
- http://mypy.readthedocs.io/en/latest/getting_started.html
312+
313+
For more details on both running mypy and using the flags below, see:
314+
315+
- http://mypy.readthedocs.io/en/latest/running_mypy.html
316+
- http://mypy.readthedocs.io/en/latest/command_line.html
317+
318+
You can also use a config file to configure mypy instead of using
319+
command line flags. For more details, see:
320+
321+
- http://mypy.readthedocs.io/en/latest/config_file.html
322+
"""
323+
324+
FOOTER = """environment variables:
325+
Define MYPYPATH for additional module search path entries."""
326+
327+
300328
def process_options(args: List[str],
301329
require_targets: bool = True,
302330
server_options: bool = False,
@@ -308,7 +336,10 @@ def process_options(args: List[str],
308336
call fscache.set_package_root() to set the cache's package root.
309337
"""
310338

311-
parser = argparse.ArgumentParser(prog='mypy', epilog=FOOTER,
339+
parser = argparse.ArgumentParser(prog='mypy',
340+
usage=HEADER,
341+
description=DESCRIPTION,
342+
epilog=FOOTER,
312343
fromfile_prefix_chars='@',
313344
formatter_class=AugmentedHelpFormatter)
314345

@@ -456,6 +487,9 @@ def add_invertible_flag(flag: str,
456487
help="warn if missing type annotation in typeshed, only relevant with"
457488
" --check-untyped-defs enabled",
458489
group=untyped_group)
490+
add_invertible_flag('--disallow-untyped-decorators', default=False, strict_flag=True,
491+
help="disallow decorating typed functions with untyped decorators",
492+
group=untyped_group)
459493

460494
none_group = parser.add_argument_group(
461495
title='None and Optional handling',
@@ -481,23 +515,27 @@ def add_invertible_flag(flag: str,
481515
add_invertible_flag('--warn-redundant-casts', default=False, strict_flag=True,
482516
help="warn about casting an expression to its inferred type",
483517
group=lint_group)
518+
add_invertible_flag('--warn-unused-ignores', default=False, strict_flag=True,
519+
help="warn about unneeded '# type: ignore' comments",
520+
group=lint_group)
484521
add_invertible_flag('--no-warn-no-return', dest='warn_no_return', default=True,
485522
help="do not warn about functions that end without returning",
486523
group=lint_group)
487524
add_invertible_flag('--warn-return-any', default=False, strict_flag=True,
488525
help="warn about returning values of type Any"
489526
" from non-Any typed functions",
490527
group=lint_group)
491-
add_invertible_flag('--warn-unused-ignores', default=False, strict_flag=True,
492-
help="warn about unneeded '# type: ignore' comments",
493-
group=lint_group)
494528

529+
# Note: this group is intentionally added here even though we don't add
530+
# --strict to this group near the end.
531+
#
532+
# That way, this group will appear after the various strictness groups
533+
# but before the remaining flags.
534+
# We add `--strict` near the end so we don't accidentally miss any strictness
535+
# flags that are added after this group.
495536
strictness_group = parser.add_argument_group(
496537
title='other strictness checks',
497538
description="Other miscellaneous strictness checks.")
498-
add_invertible_flag('--disallow-untyped-decorators', default=False, strict_flag=True,
499-
help="disallow decorating typed functions with untyped decorators",
500-
group=strictness_group)
501539

502540
incremental_group = parser.add_argument_group(
503541
title='incremental mode',
@@ -553,19 +591,6 @@ def add_invertible_flag(flag: str,
553591
help="show column numbers in error messages",
554592
group=error_group)
555593

556-
analysis_group = parser.add_argument_group(
557-
title='extra analysis',
558-
description="Extract additional information and analysis.")
559-
analysis_group.add_argument(
560-
'--stats', action='store_true', dest='dump_type_stats', help=argparse.SUPPRESS)
561-
analysis_group.add_argument(
562-
'--inferstats', action='store_true', dest='dump_inference_stats',
563-
help=argparse.SUPPRESS)
564-
analysis_group.add_argument(
565-
'--find-occurrences', metavar='CLASS.MEMBER',
566-
dest='special-opts:find_occurrences',
567-
help="print out all usages of a class member (experimental)")
568-
569594
strict_help = "strict mode; enables the following flags: {}".format(
570595
", ".join(strict_flag_names))
571596
strictness_group.add_argument(
@@ -588,6 +613,10 @@ def add_invertible_flag(flag: str,
588613
other_group.add_argument(
589614
'--scripts-are-modules', action='store_true',
590615
help="script x becomes module x instead of __main__")
616+
other_group.add_argument(
617+
'--find-occurrences', metavar='CLASS.MEMBER',
618+
dest='special-opts:find_occurrences',
619+
help="print out all usages of a class member (experimental)")
591620

592621
if server_options:
593622
# TODO: This flag is superfluous; remove after a short transition (2018-03-16)
@@ -599,6 +628,11 @@ def add_invertible_flag(flag: str,
599628
help="use the cache in fine-grained incremental mode")
600629

601630
# hidden options
631+
parser.add_argument(
632+
'--stats', action='store_true', dest='dump_type_stats', help=argparse.SUPPRESS)
633+
parser.add_argument(
634+
'--inferstats', action='store_true', dest='dump_inference_stats',
635+
help=argparse.SUPPRESS)
602636
# --debug-cache will disable any cache-related compressions/optimizations,
603637
# which will make the cache writing process output pretty-printed JSON (which
604638
# is easier to debug).

0 commit comments

Comments
 (0)