Skip to content

Fix config file parsing of disallow_any/disallow_untyped_defs combination #4076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mypy/test/testcmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion mypy/test/testpythoneval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions mypy_self_check.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
12 changes: 12 additions & 0 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -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