From 752ea72078ccef03621f3d9a2e064011cdca0a31 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Wed, 1 Aug 2018 12:10:03 -0700 Subject: [PATCH 1/3] sort module level options --- mypy/options.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/mypy/options.py b/mypy/options.py index 3b07ed5fac5b..3b4186c0fd2a 100644 --- a/mypy/options.py +++ b/mypy/options.py @@ -18,32 +18,33 @@ class Options: """Options collected from flags.""" PER_MODULE_OPTIONS = { - "ignore_missing_imports", - "follow_imports", - "follow_imports_for_stubs", - "disallow_any_generics", - "disallow_any_unimported", - "disallow_any_expr", + # Please keep this list sorted + "always_false", + "always_true", + "check_untyped_defs", + "debug_cache", "disallow_any_decorated", "disallow_any_explicit", + "disallow_any_expr", + "disallow_any_generics", + "disallow_any_unimported", "disallow_subclassing_any", "disallow_untyped_calls", + "disallow_untyped_decorators", "disallow_untyped_defs", - "check_untyped_defs", - "debug_cache", - "strict_optional_whitelist", + "follow_imports", + "follow_imports_for_stubs", + "ignore_errors", + "ignore_missing_imports", + "local_partial_types", + "no_implicit_optional", "show_none_errors", + "strict_boolean", + "strict_optional", + "strict_optional_whitelist", "warn_no_return", "warn_return_any", "warn_unused_ignores", - "ignore_errors", - "strict_boolean", - "no_implicit_optional", - "always_true", - "always_false", - "strict_optional", - "disallow_untyped_decorators", - "local_partial_types", } OPTIONS_AFFECTING_CACHE = ((PER_MODULE_OPTIONS | From 3bc869bbfd75f1500fc0162171a9fe88c45564d9 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Wed, 1 Aug 2018 12:12:17 -0700 Subject: [PATCH 2/3] Invalidate the cache if disallow_incomplete_defs changes --- docs/source/config_file.rst | 4 ++++ mypy/options.py | 1 + 2 files changed, 5 insertions(+) diff --git a/docs/source/config_file.rst b/docs/source/config_file.rst index dcd152328693..b110e530aa30 100644 --- a/docs/source/config_file.rst +++ b/docs/source/config_file.rst @@ -219,6 +219,10 @@ overridden by the pattern sections matching the module name. - ``disallow_any_generics`` (Boolean, default false) disallows usage of generic types that do not specify explicit type parameters. +- ``disallow_incomplete_defs`` (Boolean, default false) disallow defining + functions with incomplete type annotations. See + :ref:`--disallow-incomplete-defs ` option. + - ``disallow_subclassing_any`` (Boolean, default False) disallows subclassing a value of type ``Any``. See :ref:`--disallow-subclassing-any ` option. diff --git a/mypy/options.py b/mypy/options.py index 3b4186c0fd2a..9171dd865cdd 100644 --- a/mypy/options.py +++ b/mypy/options.py @@ -28,6 +28,7 @@ class Options: "disallow_any_expr", "disallow_any_generics", "disallow_any_unimported", + "disallow_incomplete_defs", "disallow_subclassing_any", "disallow_untyped_calls", "disallow_untyped_decorators", From a3a776112200a3fd3e59bc56b1e83b22f3c9cd2b Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Fri, 3 Aug 2018 08:26:39 -0700 Subject: [PATCH 3/3] Add test showing disallow_incomplete_defs is module scoped --- test-data/unit/check-flags.test | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test-data/unit/check-flags.test b/test-data/unit/check-flags.test index 3cc5867416e7..4520fd3a5d71 100644 --- a/test-data/unit/check-flags.test +++ b/test-data/unit/check-flags.test @@ -471,6 +471,23 @@ if z: # E: Condition must be a boolean [builtins fixtures/bool.pyi] +[case testPerFileIncompleteDefsBasic] +# flags: --config-file tmp/mypy.ini +import standard, incomplete + +[file standard.py] +def incomplete(x) -> int: + return 0 +[file incomplete.py] +def incomplete(x) -> int: # E: Function is missing a type annotation for one or more arguments + return 0 +[file mypy.ini] +[[mypy] +disallow_incomplete_defs = False +[[mypy-incomplete] +disallow_incomplete_defs = True + + [case testPerFileStrictOptionalBasic] # flags: --config-file tmp/mypy.ini import standard, optional