@@ -148,9 +148,6 @@ def type_check_only(sources: List[BuildSource], bin_dir: Optional[str],
148
148
fscache = fscache )
149
149
150
150
151
- FOOTER = "environment variables: Define MYPYPATH for additional module search path entries."
152
-
153
-
154
151
class SplitNamespace (argparse .Namespace ):
155
152
def __init__ (self , standard_namespace : object , alt_namespace : object , alt_prefix : str ) -> None :
156
153
self .__dict__ ['_standard_namespace' ] = standard_namespace
@@ -195,7 +192,7 @@ def parse_version(v: str) -> Tuple[int, int]:
195
192
196
193
197
194
# Make the help output a little less jarring.
198
- class AugmentedHelpFormatter (argparse .HelpFormatter ):
195
+ class AugmentedHelpFormatter (argparse .RawDescriptionHelpFormatter ):
199
196
def __init__ (self , prog : str ) -> None :
200
197
super ().__init__ (prog = prog , max_help_position = 28 )
201
198
@@ -297,6 +294,37 @@ def infer_python_version_and_executable(options: Options,
297
294
options .python_executable = special_opts .python_executable
298
295
299
296
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
+
300
328
def process_options (args : List [str ],
301
329
require_targets : bool = True ,
302
330
server_options : bool = False ,
@@ -308,7 +336,10 @@ def process_options(args: List[str],
308
336
call fscache.set_package_root() to set the cache's package root.
309
337
"""
310
338
311
- parser = argparse .ArgumentParser (prog = 'mypy' , epilog = FOOTER ,
339
+ parser = argparse .ArgumentParser (prog = 'mypy' ,
340
+ usage = HEADER ,
341
+ description = DESCRIPTION ,
342
+ epilog = FOOTER ,
312
343
fromfile_prefix_chars = '@' ,
313
344
formatter_class = AugmentedHelpFormatter )
314
345
@@ -456,6 +487,9 @@ def add_invertible_flag(flag: str,
456
487
help = "warn if missing type annotation in typeshed, only relevant with"
457
488
" --check-untyped-defs enabled" ,
458
489
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 )
459
493
460
494
none_group = parser .add_argument_group (
461
495
title = 'None and Optional handling' ,
@@ -481,23 +515,27 @@ def add_invertible_flag(flag: str,
481
515
add_invertible_flag ('--warn-redundant-casts' , default = False , strict_flag = True ,
482
516
help = "warn about casting an expression to its inferred type" ,
483
517
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 )
484
521
add_invertible_flag ('--no-warn-no-return' , dest = 'warn_no_return' , default = True ,
485
522
help = "do not warn about functions that end without returning" ,
486
523
group = lint_group )
487
524
add_invertible_flag ('--warn-return-any' , default = False , strict_flag = True ,
488
525
help = "warn about returning values of type Any"
489
526
" from non-Any typed functions" ,
490
527
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 )
494
528
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.
495
536
strictness_group = parser .add_argument_group (
496
537
title = 'other strictness checks' ,
497
538
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 )
501
539
502
540
incremental_group = parser .add_argument_group (
503
541
title = 'incremental mode' ,
@@ -553,19 +591,6 @@ def add_invertible_flag(flag: str,
553
591
help = "show column numbers in error messages" ,
554
592
group = error_group )
555
593
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
-
569
594
strict_help = "strict mode; enables the following flags: {}" .format (
570
595
", " .join (strict_flag_names ))
571
596
strictness_group .add_argument (
@@ -588,6 +613,10 @@ def add_invertible_flag(flag: str,
588
613
other_group .add_argument (
589
614
'--scripts-are-modules' , action = 'store_true' ,
590
615
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)" )
591
620
592
621
if server_options :
593
622
# TODO: This flag is superfluous; remove after a short transition (2018-03-16)
@@ -599,6 +628,11 @@ def add_invertible_flag(flag: str,
599
628
help = "use the cache in fine-grained incremental mode" )
600
629
601
630
# 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 )
602
636
# --debug-cache will disable any cache-related compressions/optimizations,
603
637
# which will make the cache writing process output pretty-printed JSON (which
604
638
# is easier to debug).
0 commit comments