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 3b07ed5fac5b..9171dd865cdd 100644 --- a/mypy/options.py +++ b/mypy/options.py @@ -18,32 +18,34 @@ 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_incomplete_defs", "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 | 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