Skip to content

Commit 2714daf

Browse files
asottilegvanrossum
authored andcommitted
Make disallow_incomplete_defs a per-module flag (#5414)
This invalidates the cache if disallow_incomplete_defs changes, fixing #5413.
1 parent 573be3e commit 2714daf

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

docs/source/config_file.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ overridden by the pattern sections matching the module name.
219219
- ``disallow_any_generics`` (Boolean, default false) disallows usage of generic types that
220220
do not specify explicit type parameters.
221221

222+
- ``disallow_incomplete_defs`` (Boolean, default false) disallow defining
223+
functions with incomplete type annotations. See
224+
:ref:`--disallow-incomplete-defs <disallow-incomplete-defs>` option.
225+
222226
- ``disallow_subclassing_any`` (Boolean, default False) disallows
223227
subclassing a value of type ``Any``. See
224228
:ref:`--disallow-subclassing-any <disallow-subclassing-any>` option.

mypy/options.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,34 @@ class Options:
1818
"""Options collected from flags."""
1919

2020
PER_MODULE_OPTIONS = {
21-
"ignore_missing_imports",
22-
"follow_imports",
23-
"follow_imports_for_stubs",
24-
"disallow_any_generics",
25-
"disallow_any_unimported",
26-
"disallow_any_expr",
21+
# Please keep this list sorted
22+
"always_false",
23+
"always_true",
24+
"check_untyped_defs",
25+
"debug_cache",
2726
"disallow_any_decorated",
2827
"disallow_any_explicit",
28+
"disallow_any_expr",
29+
"disallow_any_generics",
30+
"disallow_any_unimported",
31+
"disallow_incomplete_defs",
2932
"disallow_subclassing_any",
3033
"disallow_untyped_calls",
34+
"disallow_untyped_decorators",
3135
"disallow_untyped_defs",
32-
"check_untyped_defs",
33-
"debug_cache",
34-
"strict_optional_whitelist",
36+
"follow_imports",
37+
"follow_imports_for_stubs",
38+
"ignore_errors",
39+
"ignore_missing_imports",
40+
"local_partial_types",
41+
"no_implicit_optional",
3542
"show_none_errors",
43+
"strict_boolean",
44+
"strict_optional",
45+
"strict_optional_whitelist",
3646
"warn_no_return",
3747
"warn_return_any",
3848
"warn_unused_ignores",
39-
"ignore_errors",
40-
"strict_boolean",
41-
"no_implicit_optional",
42-
"always_true",
43-
"always_false",
44-
"strict_optional",
45-
"disallow_untyped_decorators",
46-
"local_partial_types",
4749
}
4850

4951
OPTIONS_AFFECTING_CACHE = ((PER_MODULE_OPTIONS |

test-data/unit/check-flags.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,23 @@ if z: # E: Condition must be a boolean
471471
[builtins fixtures/bool.pyi]
472472

473473

474+
[case testPerFileIncompleteDefsBasic]
475+
# flags: --config-file tmp/mypy.ini
476+
import standard, incomplete
477+
478+
[file standard.py]
479+
def incomplete(x) -> int:
480+
return 0
481+
[file incomplete.py]
482+
def incomplete(x) -> int: # E: Function is missing a type annotation for one or more arguments
483+
return 0
484+
[file mypy.ini]
485+
[[mypy]
486+
disallow_incomplete_defs = False
487+
[[mypy-incomplete]
488+
disallow_incomplete_defs = True
489+
490+
474491
[case testPerFileStrictOptionalBasic]
475492
# flags: --config-file tmp/mypy.ini
476493
import standard, optional

0 commit comments

Comments
 (0)