diff --git a/mypy/main.py b/mypy/main.py index b194dbed9892..60bf8a22e0bd 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -750,7 +750,13 @@ def parse_section(prefix: str, template: Options, print("%s: %s: %s" % (prefix, key, err), file=sys.stderr) continue if key == 'disallow_any': - results['disallow_untyped_defs'] = v and 'unannotated' in v + # "disallow_any = " should disable all disallow_any options, including untyped defs, + # given in a more general config. + if not v: + results['disallow_untyped_defs'] = False + # If "unannotated" is explicitly given, turn on disallow_untyped_defs. + elif 'unannotated' in v: + results['disallow_untyped_defs'] = True if key == 'silent_imports': print("%s: silent_imports has been replaced by " "ignore_missing_imports=True; follow_imports=skip" % prefix, file=sys.stderr) diff --git a/mypy/test/testcmdline.py b/mypy/test/testcmdline.py index 5bf638a09f18..26f1780559e1 100644 --- a/mypy/test/testcmdline.py +++ b/mypy/test/testcmdline.py @@ -41,7 +41,7 @@ def cases(cls) -> List[DataDrivenTestCase]: native_sep=True) return c - def run_case(self, testcase: DataDrivenTestCase): + def run_case(self, testcase: DataDrivenTestCase) -> None: test_python_evaluation(testcase) diff --git a/mypy/test/testpythoneval.py b/mypy/test/testpythoneval.py index f2710432a532..be32252a21b5 100644 --- a/mypy/test/testpythoneval.py +++ b/mypy/test/testpythoneval.py @@ -49,7 +49,7 @@ def cases(cls) -> List[DataDrivenTestCase]: test_python_evaluation, test_temp_dir, True) return c - def run_case(self, testcase: DataDrivenTestCase): + def run_case(self, testcase: DataDrivenTestCase) -> None: test_python_evaluation(testcase) diff --git a/mypy/types.py b/mypy/types.py index 67efd22da649..e5cc8ed793c6 100644 --- a/mypy/types.py +++ b/mypy/types.py @@ -1411,7 +1411,7 @@ def resolve(self, resolved: Type) -> None: def accept(self, visitor: 'TypeVisitor[T]') -> T: return visitor.visit_forwardref_type(self) - def serialize(self): + def serialize(self) -> str: name = self.unbound.name # We should never get here since all forward references should be resolved # and removed during semantic analysis. diff --git a/mypy_self_check.ini b/mypy_self_check.ini index bb30adf177e7..6b871f00914e 100644 --- a/mypy_self_check.ini +++ b/mypy_self_check.ini @@ -7,6 +7,7 @@ no_implicit_optional = True disallow_any = generics, unimported warn_redundant_casts = True warn_unused_ignores = True +warn_unused_configs = True # historical exception [mypy-mypy.semanal] @@ -17,3 +18,7 @@ strict_optional = False [mypy-mypy.semanal_pass3] strict_optional = False + +# needs py2 compatibility +[mypy-mypy.test.testextensions] +disallow_untyped_defs = False diff --git a/test-data/unit/cmdline.test b/test-data/unit/cmdline.test index 1bd5b9c5ad59..8464fe00cf2e 100644 --- a/test-data/unit/cmdline.test +++ b/test-data/unit/cmdline.test @@ -1078,3 +1078,15 @@ ignore_errors = True ignore_errors = False [out] a/b/c/d/e/__init__.py:1: error: "int" not callable + +[case testDisallowUntypedDefsAndGenerics] +# cmd: mypy a.py +[file mypy.ini] +[[mypy] +disallow_untyped_defs = True +disallow_any = generics +[file a.py] +def get_tasks(self): + return 'whatever' +[out] +a.py:1: error: Function is missing a type annotation