Skip to content

Commit 47e53f8

Browse files
JelleZijlstragvanrossum
authored andcommitted
Fix config file parsing of disallow_any/disallow_untyped_defs combination (#4076)
Fixes #4075. There's a follow-up item to just get rid of `--disallow-any=unannotated` completely, but let's do that together with #4089.
1 parent 1993fdf commit 47e53f8

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

mypy/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,13 @@ def parse_section(prefix: str, template: Options,
750750
print("%s: %s: %s" % (prefix, key, err), file=sys.stderr)
751751
continue
752752
if key == 'disallow_any':
753-
results['disallow_untyped_defs'] = v and 'unannotated' in v
753+
# "disallow_any = " should disable all disallow_any options, including untyped defs,
754+
# given in a more general config.
755+
if not v:
756+
results['disallow_untyped_defs'] = False
757+
# If "unannotated" is explicitly given, turn on disallow_untyped_defs.
758+
elif 'unannotated' in v:
759+
results['disallow_untyped_defs'] = True
754760
if key == 'silent_imports':
755761
print("%s: silent_imports has been replaced by "
756762
"ignore_missing_imports=True; follow_imports=skip" % prefix, file=sys.stderr)

mypy/test/testcmdline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def cases(cls) -> List[DataDrivenTestCase]:
4141
native_sep=True)
4242
return c
4343

44-
def run_case(self, testcase: DataDrivenTestCase):
44+
def run_case(self, testcase: DataDrivenTestCase) -> None:
4545
test_python_evaluation(testcase)
4646

4747

mypy/test/testpythoneval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def cases(cls) -> List[DataDrivenTestCase]:
4949
test_python_evaluation, test_temp_dir, True)
5050
return c
5151

52-
def run_case(self, testcase: DataDrivenTestCase):
52+
def run_case(self, testcase: DataDrivenTestCase) -> None:
5353
test_python_evaluation(testcase)
5454

5555

mypy/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ def resolve(self, resolved: Type) -> None:
14111411
def accept(self, visitor: 'TypeVisitor[T]') -> T:
14121412
return visitor.visit_forwardref_type(self)
14131413

1414-
def serialize(self):
1414+
def serialize(self) -> str:
14151415
name = self.unbound.name
14161416
# We should never get here since all forward references should be resolved
14171417
# and removed during semantic analysis.

mypy_self_check.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ no_implicit_optional = True
77
disallow_any = generics, unimported
88
warn_redundant_casts = True
99
warn_unused_ignores = True
10+
warn_unused_configs = True
1011

1112
# historical exception
1213
[mypy-mypy.semanal]
@@ -17,3 +18,7 @@ strict_optional = False
1718

1819
[mypy-mypy.semanal_pass3]
1920
strict_optional = False
21+
22+
# needs py2 compatibility
23+
[mypy-mypy.test.testextensions]
24+
disallow_untyped_defs = False

test-data/unit/cmdline.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,3 +1078,15 @@ ignore_errors = True
10781078
ignore_errors = False
10791079
[out]
10801080
a/b/c/d/e/__init__.py:1: error: "int" not callable
1081+
1082+
[case testDisallowUntypedDefsAndGenerics]
1083+
# cmd: mypy a.py
1084+
[file mypy.ini]
1085+
[[mypy]
1086+
disallow_untyped_defs = True
1087+
disallow_any = generics
1088+
[file a.py]
1089+
def get_tasks(self):
1090+
return 'whatever'
1091+
[out]
1092+
a.py:1: error: Function is missing a type annotation

0 commit comments

Comments
 (0)