Skip to content
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

Fix strict none errors in the test subpackage. #2200

Merged
merged 4 commits into from
Oct 3, 2016
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
5 changes: 5 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[mypy]
show_none_errors = False

[mypy-mypy/test/*]
show_none_errors = True
2 changes: 1 addition & 1 deletion mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ def find_cache_meta(id: str, path: str, manager: BuildManager) -> Optional[Cache
return m


def is_meta_fresh(meta: CacheMeta, id: str, path: str, manager: BuildManager) -> bool:
def is_meta_fresh(meta: Optional[CacheMeta], id: str, path: str, manager: BuildManager) -> bool:
if meta is None:
return False

Expand Down
30 changes: 19 additions & 11 deletions mypy/test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,15 @@ def parse_test_cases(
while i < len(p) and p[i].id != 'case':
if p[i].id == 'file':
# Record an extra file needed for the test case.
files.append((os.path.join(base_path, p[i].arg),
arg = p[i].arg
assert arg is not None
files.append((os.path.join(base_path, arg),
'\n'.join(p[i].data)))
elif p[i].id in ('builtins', 'builtins_py2'):
# Use a custom source file for the std module.
mpath = os.path.join(os.path.dirname(path), p[i].arg)
arg = p[i].arg
assert arg is not None
mpath = os.path.join(os.path.dirname(path), arg)
if p[i].id == 'builtins':
fnam = 'builtins.pyi'
else:
Expand All @@ -66,15 +70,17 @@ def parse_test_cases(
with open(mpath) as f:
files.append((os.path.join(base_path, fnam), f.read()))
elif p[i].id == 'stale':
if p[i].arg is None:
arg = p[i].arg
if arg is None:
stale_modules = set()
else:
stale_modules = {item.strip() for item in p[i].arg.split(',')}
stale_modules = {item.strip() for item in arg.split(',')}
elif p[i].id == 'rechecked':
if p[i].arg is None:
arg = p[i].arg
if arg is None:
rechecked_modules = set()
else:
rechecked_modules = {item.strip() for item in p[i].arg.split(',')}
rechecked_modules = {item.strip() for item in arg.split(',')}
elif p[i].id == 'out' or p[i].id == 'out1':
tcout = p[i].data
if native_sep and os.path.sep == '\\':
Expand All @@ -95,7 +101,9 @@ def parse_test_cases(
# If the set of rechecked modules isn't specified, make it the same as the set of
# modules with a stale public interface.
rechecked_modules = stale_modules
if stale_modules is not None and not stale_modules.issubset(rechecked_modules):
if (stale_modules is not None
and rechecked_modules is not None
and not stale_modules.issubset(rechecked_modules)):
raise ValueError(
'Stale modules must be a subset of rechecked modules ({})'.format(path))

Expand Down Expand Up @@ -225,15 +233,15 @@ class TestItem:
"""

id = ''
arg = ''
arg = '' # type: Optional[str]

# Text data, array of 8-bit strings
data = None # type: List[str]

file = ''
line = 0 # Line number in file

def __init__(self, id: str, arg: str, data: List[str], file: str,
def __init__(self, id: str, arg: Optional[str], data: List[str], file: str,
line: int) -> None:
self.id = id
self.arg = arg
Expand All @@ -248,8 +256,8 @@ def parse_test_data(l: List[str], fnam: str) -> List[TestItem]:
ret = [] # type: List[TestItem]
data = [] # type: List[str]

id = None # type: str
arg = None # type: str
id = None # type: Optional[str]
arg = None # type: Optional[str]

i = 0
i0 = 0
Expand Down
11 changes: 6 additions & 5 deletions mypy/test/testcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import typed_ast
import typed_ast.ast35

from typing import Tuple, List, Dict, Set
from typing import Dict, List, Optional, Set, Tuple

from mypy import build, defaults
from mypy.main import parse_version, process_options
Expand Down Expand Up @@ -149,15 +149,15 @@ def run_case_once(self, testcase: DataDrivenTestCase, incremental=0) -> None:
sources = []
for module_name, program_path, program_text in module_data:
# Always set to none so we're forced to reread the module in incremental mode
program_text = None if incremental else program_text
sources.append(BuildSource(program_path, module_name, program_text))
sources.append(BuildSource(program_path, module_name,
None if incremental else program_text))
res = None
Copy link
Member Author

@gvanrossum gvanrossum Sep 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refactor was needed because program_text is previously inferred as str, and that's correct. So this is technically a case of reusing the same variable name with a different type (#1174). [UPDATE: This comment should be one line up.]

try:
res = build.build(sources=sources,
options=options,
alt_lib_path=test_temp_dir)
a = res.errors
except CompileError as e:
res = None
a = e.messages
a = normalize_error_messages(a)

Expand Down Expand Up @@ -191,7 +191,8 @@ def run_case_once(self, testcase: DataDrivenTestCase, incremental=0) -> None:
testcase.expected_stale_modules,
res.manager.stale_modules)

def check_module_equivalence(self, name: str, expected: Set[str], actual: Set[str]) -> None:
def check_module_equivalence(self, name: str,
expected: Optional[Set[str]], actual: Set[str]) -> None:
if expected is not None:
assert_string_arrays_equal(
list(sorted(expected)),
Expand Down
2 changes: 1 addition & 1 deletion mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ class CallableType(FunctionLike):
def __init__(self,
arg_types: List[Type],
arg_kinds: List[int],
arg_names: List[str],
arg_names: List[Optional[str]],
ret_type: Type,
fallback: Instance,
name: str = None,
Expand Down
5 changes: 3 additions & 2 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def add_mypy_modules(self, name: str, modules: Iterable[str],
args = list(itertools.chain(*(['-m', mod] for mod in modules)))
self.add_mypy_cmd(name, args, cwd=cwd)

def add_mypy_package(self, name: str, packagename: str) -> None:
self.add_mypy_cmd(name, ['-p', packagename])
def add_mypy_package(self, name: str, packagename: str, *flags: str) -> None:
self.add_mypy_cmd(name, ['-p', packagename] + list(flags))

def add_mypy_string(self, name: str, *args: str, cwd: Optional[str] = None) -> None:
self.add_mypy_cmd(name, ['-c'] + list(args), cwd=cwd)
Expand Down Expand Up @@ -168,6 +168,7 @@ def add_basic(driver: Driver) -> None:

def add_selftypecheck(driver: Driver) -> None:
driver.add_mypy_package('package mypy', 'mypy')
driver.add_mypy_package('package mypy', 'mypy', '--strict-optional')


def find_files(base: str, prefix: str = '', suffix: str = '') -> List[str]:
Expand Down