From fb616ed19286a36f18d778dc4baa919b6bbd4824 Mon Sep 17 00:00:00 2001 From: David Fisher Date: Wed, 18 Jan 2017 15:06:15 -0800 Subject: [PATCH 1/9] Add inverted options and strict mode --- docs/source/command_line.rst | 5 ++- mypy/main.py | 65 ++++++++++++++++++++++++++---------- 2 files changed, 51 insertions(+), 19 deletions(-) diff --git a/docs/source/command_line.rst b/docs/source/command_line.rst index b26b6bf7b65f..a950f8a44296 100644 --- a/docs/source/command_line.rst +++ b/docs/source/command_line.rst @@ -16,7 +16,7 @@ flag (or its long form ``--help``):: [--warn-incomplete-stub] [--warn-redundant-casts] [--warn-no-return] [--warn-unused-ignores] [--show-error-context] [--fast-parser] [-i] [--cache-dir DIR] [--strict-optional] - [--strict-optional-whitelist [GLOB [GLOB ...]]] + [--strict-optional-whitelist [GLOB [GLOB ...]]] [--strict] [--junit-xml JUNIT_XML] [--pdb] [--show-traceback] [--stats] [--inferstats] [--custom-typing MODULE] [--custom-typeshed-dir DIR] [--scripts-are-modules] @@ -371,6 +371,9 @@ Here are some more useful flags: type other than ``bool``. Instead use explicit checks like ``if x > 0`` or ``while x is not None``. +- ``--strict`` mode enables all optional error checking flags. You can see the + list of flags enabled by strict mode in the full ``mypy -h`` output. + For the remaining flags you can read the full ``mypy -h`` output. .. note:: diff --git a/mypy/main.py b/mypy/main.py index d6fae34b4c9a..2b141bef7c1c 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -135,6 +135,23 @@ def process_options(args: List[str], fromfile_prefix_chars='@', formatter_class=AugmentedHelpFormatter) + strict_flag_names = [] # type: List[str] + strict_flag_assignments = [] # type: List[Tuple[str, bool]] + + def add_invertable_flag(flag, *, inverse, default, dest=None, help, strict_flag=False): + arg = parser.add_argument(flag, + action='store_false' if default else 'store_true', + dest=dest, + help=help + " (inverse: {})".format(inverse)) + dest = arg.dest + arg = parser.add_argument(inverse, + action='store_true' if default else 'store_false', + dest=dest, + help=argparse.SUPPRESS) + if strict_flag: + strict_flag_names.append(flag) + strict_flag_assignments.append((dest, not default)) + # Unless otherwise specified, arguments will be parsed directly onto an # Options object. Options that require further processing should have # their `dest` prefixed with `special-opts:`, which will cause them to be @@ -154,37 +171,44 @@ def process_options(args: List[str], help="silently ignore imports of missing modules") parser.add_argument('--follow-imports', choices=['normal', 'silent', 'skip', 'error'], default='normal', help="how to treat imports (default normal)") - parser.add_argument('--disallow-untyped-calls', action='store_true', + add_invertable_flag('--disallow-untyped-calls', inverse='--allow-untyped-calls', + default=False, strict_flag=True, help="disallow calling functions without type annotations" " from functions with type annotations") - parser.add_argument('--disallow-untyped-defs', action='store_true', + add_invertable_flag('--disallow-untyped-defs', inverse='--allow-untyped-defs', + default=False, strict_flag=True, help="disallow defining functions without type annotations" " or with incomplete type annotations") - parser.add_argument('--check-untyped-defs', action='store_true', + add_invertable_flag('--check-untyped-defs', inverse='--ignore-untyped-defs', + default=False, strict_flag=True, help="type check the interior of functions without type annotations") - parser.add_argument('--disallow-subclassing-any', action='store_true', + add_invertable_flag('--disallow-subclassing-any', inverse='--allow-subclassing-any', + default=False, strict_flag=True, help="disallow subclassing values of type 'Any' when defining classes") - parser.add_argument('--warn-incomplete-stub', action='store_true', + add_invertable_flag('--warn-incomplete-stub', inverse='--no-warn-incomplete-stub', + default=False, help="warn if missing type annotation in typeshed, only relevant with" " --check-untyped-defs enabled") - parser.add_argument('--warn-redundant-casts', action='store_true', + add_invertable_flag('--warn-redundant-casts', inverse='--no-warn-redundant-casts', + default=False, strict_flag=True, help="warn about casting an expression to its inferred type") - parser.add_argument('--warn-no-return', action='store_true', + add_invertable_flag('--warn-no-return', inverse='--no-warn-no-return', default=False, help="warn about functions that end without returning") - parser.add_argument('--warn-unused-ignores', action='store_true', + add_invertable_flag('--warn-unused-ignores', inverse='--no-warn-unused-ignores', + default=False, strict_flag=True, help="warn about unneeded '# type: ignore' comments") - parser.add_argument('--show-error-context', action='store_false', + add_invertable_flag('--show-error-context', inverse='--hide-error-context', default=True, dest='hide_error_context', help='Precede errors with "note:" messages explaining context') - parser.add_argument('--fast-parser', action='store_true', - help="enable fast parser (recommended except on Windows)") + add_invertable_flag('--fast-parser', inverse='--old-parser', default=False, + help="enable fast parser (recommended)") parser.add_argument('-i', '--incremental', action='store_true', help="enable experimental module cache") parser.add_argument('--cache-dir', action='store', metavar='DIR', help="store module cache info in the given folder in incremental mode " "(defaults to '{}')".format(defaults.CACHE_DIR)) - parser.add_argument('--strict-optional', action='store_true', - dest='strict_optional', + add_invertable_flag('--strict-optional', inverse='--no-strict-optional', + default=False, strict_flag=True, help="enable experimental strict Optional checks") parser.add_argument('--strict-optional-whitelist', metavar='GLOB', nargs='*', help="suppress strict Optional errors in all but the provided files " @@ -207,8 +231,7 @@ def process_options(args: List[str], parser.add_argument('--config-file', help="Configuration file, must have a [mypy] section " "(defaults to {})".format(defaults.CONFIG_FILE)) - parser.add_argument('--show-column-numbers', action='store_true', - dest='show_column_numbers', + add_invertable_flag('--show-column-numbers', inverse='--hide-column-numbers', default=False, help="Show column numbers in error messages") parser.add_argument('--find-occurrences', metavar='CLASS.MEMBER', dest='special-opts:find_occurrences', @@ -216,6 +239,10 @@ def process_options(args: List[str], parser.add_argument('--strict-boolean', action='store_true', dest='strict_boolean', help='enable strict boolean checks in conditions') + strict_help = "Strict mode. Enables the following flags: {}".format( + ", ".join(strict_flag_names)) + parser.add_argument('--strict', action='store_true', dest='special-opts:strict', + help=strict_help) # hidden options # --shadow-file a.py tmp.py will typecheck tmp.py in place of a.py. # Useful for tools to make transformations to a file to get more @@ -229,9 +256,6 @@ def process_options(args: List[str], parser.add_argument('--debug-cache', action='store_true', help=argparse.SUPPRESS) # --dump-graph will dump the contents of the graph of SCCs and exit. parser.add_argument('--dump-graph', action='store_true', help=argparse.SUPPRESS) - parser.add_argument('--hide-error-context', action='store_true', - dest='hide_error_context', - help=argparse.SUPPRESS) # deprecated options parser.add_argument('-f', '--dirty-stubs', action='store_true', dest='special-opts:dirty_stubs', @@ -324,6 +348,11 @@ def process_options(args: List[str], elif code_methods > 1: parser.error("May only specify one of: module, package, files, or command.") + # Set strict flags if strict mode enabled + if special_opts.strict: + for dest, value in strict_flag_assignments: + setattr(options, dest, value) + # Set build flags. if options.strict_optional_whitelist is not None: # TODO: Deprecate, then kill this flag From 5f7939b78e106450f6977e5c2115b6b7e06cc4e5 Mon Sep 17 00:00:00 2001 From: David Fisher Date: Wed, 18 Jan 2017 15:14:32 -0800 Subject: [PATCH 2/9] I can spell --- mypy/main.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index 2b141bef7c1c..a5b92dc27db0 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -138,7 +138,7 @@ def process_options(args: List[str], strict_flag_names = [] # type: List[str] strict_flag_assignments = [] # type: List[Tuple[str, bool]] - def add_invertable_flag(flag, *, inverse, default, dest=None, help, strict_flag=False): + def add_invertible_flag(flag, *, inverse, default, dest=None, help, strict_flag=False): arg = parser.add_argument(flag, action='store_false' if default else 'store_true', dest=dest, @@ -171,43 +171,43 @@ def add_invertable_flag(flag, *, inverse, default, dest=None, help, strict_flag= help="silently ignore imports of missing modules") parser.add_argument('--follow-imports', choices=['normal', 'silent', 'skip', 'error'], default='normal', help="how to treat imports (default normal)") - add_invertable_flag('--disallow-untyped-calls', inverse='--allow-untyped-calls', + add_invertible_flag('--disallow-untyped-calls', inverse='--allow-untyped-calls', default=False, strict_flag=True, help="disallow calling functions without type annotations" " from functions with type annotations") - add_invertable_flag('--disallow-untyped-defs', inverse='--allow-untyped-defs', + add_invertible_flag('--disallow-untyped-defs', inverse='--allow-untyped-defs', default=False, strict_flag=True, help="disallow defining functions without type annotations" " or with incomplete type annotations") - add_invertable_flag('--check-untyped-defs', inverse='--ignore-untyped-defs', + add_invertible_flag('--check-untyped-defs', inverse='--ignore-untyped-defs', default=False, strict_flag=True, help="type check the interior of functions without type annotations") - add_invertable_flag('--disallow-subclassing-any', inverse='--allow-subclassing-any', + add_invertible_flag('--disallow-subclassing-any', inverse='--allow-subclassing-any', default=False, strict_flag=True, help="disallow subclassing values of type 'Any' when defining classes") - add_invertable_flag('--warn-incomplete-stub', inverse='--no-warn-incomplete-stub', + add_invertible_flag('--warn-incomplete-stub', inverse='--no-warn-incomplete-stub', default=False, help="warn if missing type annotation in typeshed, only relevant with" " --check-untyped-defs enabled") - add_invertable_flag('--warn-redundant-casts', inverse='--no-warn-redundant-casts', + add_invertible_flag('--warn-redundant-casts', inverse='--no-warn-redundant-casts', default=False, strict_flag=True, help="warn about casting an expression to its inferred type") - add_invertable_flag('--warn-no-return', inverse='--no-warn-no-return', default=False, + add_invertible_flag('--warn-no-return', inverse='--no-warn-no-return', default=False, help="warn about functions that end without returning") - add_invertable_flag('--warn-unused-ignores', inverse='--no-warn-unused-ignores', + add_invertible_flag('--warn-unused-ignores', inverse='--no-warn-unused-ignores', default=False, strict_flag=True, help="warn about unneeded '# type: ignore' comments") - add_invertable_flag('--show-error-context', inverse='--hide-error-context', default=True, + add_invertible_flag('--show-error-context', inverse='--hide-error-context', default=True, dest='hide_error_context', help='Precede errors with "note:" messages explaining context') - add_invertable_flag('--fast-parser', inverse='--old-parser', default=False, + add_invertible_flag('--fast-parser', inverse='--old-parser', default=False, help="enable fast parser (recommended)") parser.add_argument('-i', '--incremental', action='store_true', help="enable experimental module cache") parser.add_argument('--cache-dir', action='store', metavar='DIR', help="store module cache info in the given folder in incremental mode " "(defaults to '{}')".format(defaults.CACHE_DIR)) - add_invertable_flag('--strict-optional', inverse='--no-strict-optional', + add_invertible_flag('--strict-optional', inverse='--no-strict-optional', default=False, strict_flag=True, help="enable experimental strict Optional checks") parser.add_argument('--strict-optional-whitelist', metavar='GLOB', nargs='*', @@ -231,7 +231,7 @@ def add_invertable_flag(flag, *, inverse, default, dest=None, help, strict_flag= parser.add_argument('--config-file', help="Configuration file, must have a [mypy] section " "(defaults to {})".format(defaults.CONFIG_FILE)) - add_invertable_flag('--show-column-numbers', inverse='--hide-column-numbers', default=False, + add_invertible_flag('--show-column-numbers', inverse='--hide-column-numbers', default=False, help="Show column numbers in error messages") parser.add_argument('--find-occurrences', metavar='CLASS.MEMBER', dest='special-opts:find_occurrences', From ddeb35cf601cdd9e52c8acd67d65f794a17dccac Mon Sep 17 00:00:00 2001 From: David Fisher Date: Wed, 18 Jan 2017 15:32:42 -0800 Subject: [PATCH 3/9] Set strict options earlier --- mypy/main.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index a5b92dc27db0..a7ffa6ec22be 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -294,7 +294,7 @@ def add_invertible_flag(flag, *, inverse, default, dest=None, help, strict_flag= help="type-check given files or directories") # Parse arguments once into a dummy namespace so we can get the - # filename for the config file. + # filename for the config file and know if the user requested all strict options. dummy = argparse.Namespace() parser.parse_args(args, dummy) config_file = defaults.CONFIG_FILE @@ -308,6 +308,12 @@ def add_invertible_flag(flag, *, inverse, default, dest=None, help, strict_flag= if config_file and os.path.exists(config_file): parse_config_file(options, config_file) + # Set strict flags before parsing (if strict mode enabled), so other command + # line options can override. + if getattr(dummy, 'special-opts:strict'): + for dest, value in strict_flag_assignments: + setattr(options, dest, value) + # Parse command line for real, using a split namespace. special_opts = argparse.Namespace() parser.parse_args(args, SplitNamespace(options, special_opts, 'special-opts:')) @@ -348,11 +354,6 @@ def add_invertible_flag(flag, *, inverse, default, dest=None, help, strict_flag= elif code_methods > 1: parser.error("May only specify one of: module, package, files, or command.") - # Set strict flags if strict mode enabled - if special_opts.strict: - for dest, value in strict_flag_assignments: - setattr(options, dest, value) - # Set build flags. if options.strict_optional_whitelist is not None: # TODO: Deprecate, then kill this flag From 4759e37b19f05d957ab979b2fdb6e1dfaefabce3 Mon Sep 17 00:00:00 2001 From: David Fisher Date: Wed, 18 Jan 2017 15:35:02 -0800 Subject: [PATCH 4/9] Fix type errors --- mypy/main.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index a7ffa6ec22be..d068fa9794ae 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -138,13 +138,20 @@ def process_options(args: List[str], strict_flag_names = [] # type: List[str] strict_flag_assignments = [] # type: List[Tuple[str, bool]] - def add_invertible_flag(flag, *, inverse, default, dest=None, help, strict_flag=False): - arg = parser.add_argument(flag, + def add_invertible_flag(flag: str, + *, + inverse: str, + default: bool, + dest: str = None, + help: str, + strict_flag: bool = False + ) -> None: + arg = parser.add_argument(flag, # type: ignore # incorrect stub for add_argument action='store_false' if default else 'store_true', dest=dest, help=help + " (inverse: {})".format(inverse)) dest = arg.dest - arg = parser.add_argument(inverse, + arg = parser.add_argument(inverse, # type: ignore # incorrect stub for add_argument action='store_true' if default else 'store_false', dest=dest, help=argparse.SUPPRESS) From 17b9dc5d3e996ddf0901b1c2f9ae864d1fe1c3c7 Mon Sep 17 00:00:00 2001 From: David Fisher Date: Wed, 18 Jan 2017 15:47:28 -0800 Subject: [PATCH 5/9] Define inverse name programatically for consistency --- mypy/main.py | 53 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index d068fa9794ae..b9b8dface8cd 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -125,6 +125,25 @@ class AugmentedHelpFormatter(argparse.HelpFormatter): def __init__(self, prog: Optional[str]) -> None: super().__init__(prog=prog, max_help_position=28) +# Define pairs of flag prefixes with inverse meaning. +flag_prefix_pairs = [ + ('allow', 'disallow'), + ('show', 'hide'), + ('check', 'ignore') +] +flag_prefix_map = {} # type: Dict[str, str] +for a, b in flag_prefix_pairs: + flag_prefix_map[a] = b + flag_prefix_map[b] = a + +def invert_flag_name(flag: str) -> str: + split = flag[2:].split('-', 1) + if len(split) == 2: + prefix, rest = split + if prefix in flag_prefix_map: + return '--{}-{}'.format(flag_prefix_map[prefix], rest) + + return '--no-{}'.format(flag[2:]) def process_options(args: List[str], require_targets: bool = True @@ -140,12 +159,14 @@ def process_options(args: List[str], def add_invertible_flag(flag: str, *, - inverse: str, + inverse: str = None, default: bool, dest: str = None, help: str, strict_flag: bool = False ) -> None: + if inverse is None: + inverse = invert_flag_name(flag) arg = parser.add_argument(flag, # type: ignore # incorrect stub for add_argument action='store_false' if default else 'store_true', dest=dest, @@ -178,33 +199,26 @@ def add_invertible_flag(flag: str, help="silently ignore imports of missing modules") parser.add_argument('--follow-imports', choices=['normal', 'silent', 'skip', 'error'], default='normal', help="how to treat imports (default normal)") - add_invertible_flag('--disallow-untyped-calls', inverse='--allow-untyped-calls', - default=False, strict_flag=True, + add_invertible_flag('--disallow-untyped-calls', default=False, strict_flag=True, help="disallow calling functions without type annotations" " from functions with type annotations") - add_invertible_flag('--disallow-untyped-defs', inverse='--allow-untyped-defs', - default=False, strict_flag=True, + add_invertible_flag('--disallow-untyped-defs', default=False, strict_flag=True, help="disallow defining functions without type annotations" " or with incomplete type annotations") - add_invertible_flag('--check-untyped-defs', inverse='--ignore-untyped-defs', - default=False, strict_flag=True, + add_invertible_flag('--check-untyped-defs', default=False, strict_flag=True, help="type check the interior of functions without type annotations") - add_invertible_flag('--disallow-subclassing-any', inverse='--allow-subclassing-any', - default=False, strict_flag=True, + add_invertible_flag('--disallow-subclassing-any', default=False, strict_flag=True, help="disallow subclassing values of type 'Any' when defining classes") - add_invertible_flag('--warn-incomplete-stub', inverse='--no-warn-incomplete-stub', - default=False, + add_invertible_flag('--warn-incomplete-stub', default=False, help="warn if missing type annotation in typeshed, only relevant with" " --check-untyped-defs enabled") - add_invertible_flag('--warn-redundant-casts', inverse='--no-warn-redundant-casts', - default=False, strict_flag=True, + add_invertible_flag('--warn-redundant-casts', default=False, strict_flag=True, help="warn about casting an expression to its inferred type") - add_invertible_flag('--warn-no-return', inverse='--no-warn-no-return', default=False, + add_invertible_flag('--warn-no-return', default=False, help="warn about functions that end without returning") - add_invertible_flag('--warn-unused-ignores', inverse='--no-warn-unused-ignores', - default=False, strict_flag=True, + add_invertible_flag('--warn-unused-ignores', default=False, strict_flag=True, help="warn about unneeded '# type: ignore' comments") - add_invertible_flag('--show-error-context', inverse='--hide-error-context', default=True, + add_invertible_flag('--show-error-context', default=True, dest='hide_error_context', help='Precede errors with "note:" messages explaining context') add_invertible_flag('--fast-parser', inverse='--old-parser', default=False, @@ -214,8 +228,7 @@ def add_invertible_flag(flag: str, parser.add_argument('--cache-dir', action='store', metavar='DIR', help="store module cache info in the given folder in incremental mode " "(defaults to '{}')".format(defaults.CACHE_DIR)) - add_invertible_flag('--strict-optional', inverse='--no-strict-optional', - default=False, strict_flag=True, + add_invertible_flag('--strict-optional', default=False, strict_flag=True, help="enable experimental strict Optional checks") parser.add_argument('--strict-optional-whitelist', metavar='GLOB', nargs='*', help="suppress strict Optional errors in all but the provided files " @@ -238,7 +251,7 @@ def add_invertible_flag(flag: str, parser.add_argument('--config-file', help="Configuration file, must have a [mypy] section " "(defaults to {})".format(defaults.CONFIG_FILE)) - add_invertible_flag('--show-column-numbers', inverse='--hide-column-numbers', default=False, + add_invertible_flag('--show-column-numbers', default=False, help="Show column numbers in error messages") parser.add_argument('--find-occurrences', metavar='CLASS.MEMBER', dest='special-opts:find_occurrences', From b0083280114d7253edb12f639f379fc12db39e49 Mon Sep 17 00:00:00 2001 From: David Fisher Date: Wed, 18 Jan 2017 15:52:04 -0800 Subject: [PATCH 6/9] fix lint errors --- mypy/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mypy/main.py b/mypy/main.py index b9b8dface8cd..537c841de468 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -136,6 +136,7 @@ def __init__(self, prog: Optional[str]) -> None: flag_prefix_map[a] = b flag_prefix_map[b] = a + def invert_flag_name(flag: str) -> str: split = flag[2:].split('-', 1) if len(split) == 2: @@ -145,6 +146,7 @@ def invert_flag_name(flag: str) -> str: return '--no-{}'.format(flag[2:]) + def process_options(args: List[str], require_targets: bool = True ) -> Tuple[List[BuildSource], Options]: From 53697936da9b1710029853da5a39627980cf0704 Mon Sep 17 00:00:00 2001 From: David Fisher Date: Thu, 19 Jan 2017 12:27:07 -0800 Subject: [PATCH 7/9] Tweak naming and fix lint error that only appears on recent flake8 versions --- mypy/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index 537c841de468..f7074590a574 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -125,11 +125,11 @@ class AugmentedHelpFormatter(argparse.HelpFormatter): def __init__(self, prog: Optional[str]) -> None: super().__init__(prog=prog, max_help_position=28) + # Define pairs of flag prefixes with inverse meaning. flag_prefix_pairs = [ ('allow', 'disallow'), ('show', 'hide'), - ('check', 'ignore') ] flag_prefix_map = {} # type: Dict[str, str] for a, b in flag_prefix_pairs: @@ -223,7 +223,7 @@ def add_invertible_flag(flag: str, add_invertible_flag('--show-error-context', default=True, dest='hide_error_context', help='Precede errors with "note:" messages explaining context') - add_invertible_flag('--fast-parser', inverse='--old-parser', default=False, + add_invertible_flag('--fast-parser', default=False, help="enable fast parser (recommended)") parser.add_argument('-i', '--incremental', action='store_true', help="enable experimental module cache") From 2e75c8006778c1da48eafa511cb01ad8ea55595c Mon Sep 17 00:00:00 2001 From: David Fisher Date: Fri, 20 Jan 2017 14:58:46 -0800 Subject: [PATCH 8/9] Add --strict-boolean to strict mode --- mypy/main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index f7074590a574..34ededbd24bd 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -258,8 +258,7 @@ def add_invertible_flag(flag: str, parser.add_argument('--find-occurrences', metavar='CLASS.MEMBER', dest='special-opts:find_occurrences', help="print out all usages of a class member (experimental)") - parser.add_argument('--strict-boolean', action='store_true', - dest='strict_boolean', + add_invertible_flag('--strict-boolean', default=False, strict_flag=True, help='enable strict boolean checks in conditions') strict_help = "Strict mode. Enables the following flags: {}".format( ", ".join(strict_flag_names)) From 73a85a5c626116a6446baa447e1141b2f87b3c7e Mon Sep 17 00:00:00 2001 From: David Fisher Date: Fri, 20 Jan 2017 16:39:58 -0800 Subject: [PATCH 9/9] Add inversion for options that begin with --no --- mypy/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mypy/main.py b/mypy/main.py index 34ededbd24bd..ea203f0f1a44 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -143,6 +143,8 @@ def invert_flag_name(flag: str) -> str: prefix, rest = split if prefix in flag_prefix_map: return '--{}-{}'.format(flag_prefix_map[prefix], rest) + elif prefix == 'no': + return '--{}'.format(rest) return '--no-{}'.format(flag[2:])