From 90b0a499d0a4930d3d650ab4ff492bdd02a7f5ae Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 8 Oct 2017 19:52:39 -0700 Subject: [PATCH 1/3] add failing test case --- test-data/unit/cmdline.test | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test-data/unit/cmdline.test b/test-data/unit/cmdline.test index 1bd5b9c5ad59..2e94cd1cf6e4 100644 --- a/test-data/unit/cmdline.test +++ b/test-data/unit/cmdline.test @@ -1078,3 +1078,13 @@ 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): # E: Function is missing a type annotation + return 'whatever' From 17f4df850ffe91ef018aa6a60b469819cd057fc2 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 8 Oct 2017 20:22:40 -0700 Subject: [PATCH 2/3] fix the bug --- mypy/main.py | 8 +++++++- test-data/unit/cmdline.test | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) 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/test-data/unit/cmdline.test b/test-data/unit/cmdline.test index 2e94cd1cf6e4..8464fe00cf2e 100644 --- a/test-data/unit/cmdline.test +++ b/test-data/unit/cmdline.test @@ -1086,5 +1086,7 @@ a/b/c/d/e/__init__.py:1: error: "int" not callable disallow_untyped_defs = True disallow_any = generics [file a.py] -def get_tasks(self): # E: Function is missing a type annotation +def get_tasks(self): return 'whatever' +[out] +a.py:1: error: Function is missing a type annotation From e97032d7f6813a6aae824bae263aa56dc399bbb6 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 8 Oct 2017 20:24:23 -0700 Subject: [PATCH 3/3] add some missing annotations --- mypy/test/testcmdline.py | 2 +- mypy/test/testpythoneval.py | 2 +- mypy/types.py | 2 +- mypy_self_check.ini | 5 +++++ 4 files changed, 8 insertions(+), 3 deletions(-) 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 dcc845922419..1f170a0939ec 100644 --- a/mypy/types.py +++ b/mypy/types.py @@ -1398,7 +1398,7 @@ def __init__(self, link: Type) -> None: def accept(self, visitor: 'TypeVisitor[T]') -> T: return visitor.visit_forwardref_type(self) - def serialize(self): + def serialize(self) -> str: if isinstance(self.link, UnboundType): name = self.link.name if isinstance(self.link, Instance): diff --git a/mypy_self_check.ini b/mypy_self_check.ini index 6b97ed660d9b..44576b5c14ad 100644 --- a/mypy_self_check.ini +++ b/mypy_self_check.ini @@ -7,7 +7,12 @@ 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] strict_optional = False + +# needs py2 compatibility +[mypy-mypy.test.testextensions] +disallow_untyped_defs = False