Skip to content

Set python_version to default to sys.version_info #4686

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 2 commits into from
Mar 6, 2018
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
2 changes: 1 addition & 1 deletion mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self) -> None:

# -- build options --
self.build_type = BuildType.STANDARD
self.python_version = defaults.PYTHON3_VERSION
self.python_version = sys.version_info[:2] # type: Tuple[int, int]
self.platform = sys.platform
self.custom_typing_module = None # type: Optional[str]
self.custom_typeshed_dir = None # type: Optional[str]
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from mypy import build
from mypy.build import BuildSource
from mypy.defaults import PYTHON3_VERSION
from mypy.errors import CompileError
from mypy.nodes import MypyFile
from mypy.options import Options
Expand Down Expand Up @@ -53,6 +54,7 @@ def build(self, source: str) -> Tuple[List[str], Optional[Dict[str, MypyFile]]]:
options.use_builtins_fixtures = True
options.show_traceback = True
options.cache_dir = os.devnull
options.python_version = PYTHON3_VERSION
try:
result = build.build(sources=[BuildSource('main', None, source)],
options=options,
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from mypy import build
from mypy.build import BuildManager, BuildSource, State, Graph
from mypy.defaults import PYTHON3_VERSION
from mypy.errors import Errors, CompileError
from mypy.nodes import (
Node, MypyFile, SymbolTable, SymbolTableNode, TypeInfo, Expression, Var, TypeVarExpr,
Expand Down Expand Up @@ -106,6 +107,7 @@ def build(self, source: str) -> Tuple[List[str], Optional[BuildManager], Dict[st
options.fine_grained_incremental = True
options.use_builtins_fixtures = True
options.show_traceback = True
options.python_version = PYTHON3_VERSION
main_path = os.path.join(test_temp_dir, 'main')
with open(main_path, 'w') as f:
f.write(source)
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testpythoneval.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import pytest # type: ignore # no pytest in typeshed
from typing import Dict, List, Tuple, Optional

from mypy.defaults import PYTHON3_VERSION
from mypy.test.config import test_temp_dir
from mypy.test.data import DataDrivenTestCase, DataSuite
from mypy.test.helpers import assert_string_arrays_equal
Expand Down Expand Up @@ -60,6 +61,7 @@ def test_python_evaluation(testcase: DataDrivenTestCase) -> None:
return
else:
interpreter = python3_path
mypy_cmdline.append('--python-version={}'.format('.'.join(map(str, PYTHON3_VERSION))))

# Write the program to a file.
program = '_' + testcase.name + '.py'
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testsemanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from mypy import build
from mypy.build import BuildSource
from mypy.defaults import PYTHON3_VERSION
from mypy.test.helpers import (
assert_string_arrays_equal, normalize_error_messages, testfile_pyversion,
)
Expand Down Expand Up @@ -38,6 +39,7 @@ def get_semanal_options() -> Options:
options.use_builtins_fixtures = True
options.semantic_analysis_only = True
options.show_traceback = True
options.python_version = PYTHON3_VERSION
return options


Expand Down
2 changes: 1 addition & 1 deletion mypy/waiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def load_log_file(self) -> Optional[List[Dict[str, Dict[str, Any]]]]:
test_log = json.load(fp)
except FileNotFoundError:
test_log = []
except json.JSONDecodeError:
except ValueError:
print('corrupt test log file {}'.format(self.FULL_LOG_FILENAME), file=sys.stderr)
test_log = []
return test_log
Expand Down
16 changes: 11 additions & 5 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ def add_mypy_cmd(self, name: str, mypy_args: List[str], cwd: Optional[str] = Non
def add_mypy(self, name: str, *args: str, cwd: Optional[str] = None) -> None:
self.add_mypy_cmd(name, list(args), cwd=cwd)

def add_mypy_modules(self, name: str, modules: Iterable[str],
cwd: Optional[str] = None) -> None:
args = list(itertools.chain(*(['-m', mod] for mod in modules)))
def add_mypy_modules(self, name: str, modules: Iterable[str], cwd: Optional[str] = None,
extra_args: Optional[List[str]] = None) -> None:
args = extra_args or []
args.extend(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, *flags: str) -> None:
Expand Down Expand Up @@ -256,7 +257,8 @@ def add_stubs(driver: Driver) -> None:
module = file_to_module(f[len(stubdir) + 1:])
modules.add(module)

driver.add_mypy_modules('stubs', sorted(modules))
# these require at least 3.5 otherwise it will fail trying to import zipapp
driver.add_mypy_modules('stubs', sorted(modules), extra_args=['--python-version=3.5'])


def add_stdlibsamples(driver: Driver) -> None:
Expand All @@ -276,7 +278,11 @@ def add_stdlibsamples(driver: Driver) -> None:

def add_samples(driver: Driver) -> None:
for f in find_files(os.path.join('test-data', 'samples'), suffix='.py'):
driver.add_mypy('file %s' % f, f)
if f == os.path.join('test-data', 'samples', 'crawl2.py'):
# This test requires 3.5 for async functions
driver.add_mypy_cmd('file {}'.format(f), ['--python-version=3.5', f])
else:
driver.add_mypy('file %s' % f, f)


def usage(status: int) -> None:
Expand Down
14 changes: 7 additions & 7 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ m.py:6: error: Explicit "Any" is not allowed
m.py:9: error: Explicit "Any" is not allowed

[case testDisallowAnyExplicitVarDeclaration]
# cmd: mypy m.py
# cmd: mypy --python-version=3.6 m.py

[file mypy.ini]
[[mypy]
Expand All @@ -601,7 +601,7 @@ m.py:3: error: Explicit "Any" is not allowed
m.py:5: error: Explicit "Any" is not allowed

[case testDisallowAnyExplicitGenericVarDeclaration]
# cmd: mypy m.py
# cmd: mypy --python-version=3.6 m.py

[file mypy.ini]
[[mypy]
Expand Down Expand Up @@ -785,7 +785,7 @@ N = TypedDict('N', {'x': str, 'y': List}) # no error
m.py:4: error: Explicit "Any" is not allowed

[case testDisallowAnyGenericsTupleNoTypeParams]
# cmd: mypy m.py
# cmd: mypy --python-version=3.6 m.py
[file mypy.ini]
[[mypy]
[[mypy-m]
Expand Down Expand Up @@ -821,7 +821,7 @@ def g(s: List[Tuple[str, str]]) -> None: pass # no error
m.py:3: error: Missing type parameters for generic type

[case testDisallowAnyGenericsTypeType]
# cmd: mypy m.py
# cmd: mypy --python-version=3.6 m.py
[file mypy.ini]
[[mypy]
[[mypy-m]
Expand Down Expand Up @@ -858,7 +858,7 @@ def g(l: L[str]) -> None: pass # no error
m.py:5: error: Missing type parameters for generic type

[case testDisallowAnyGenericsGenericAlias]
# cmd: mypy m.py
# cmd: mypy --python-version=3.6 m.py
[file mypy.ini]
[[mypy]
[[mypy-m]
Expand All @@ -882,7 +882,7 @@ m.py:7: error: Missing type parameters for generic type
m.py:11: error: Missing type parameters for generic type

[case testDisallowAnyGenericsPlainList]
# cmd: mypy m.py
# cmd: mypy --python-version=3.6 m.py
[file mypy.ini]
[[mypy]
[[mypy-m]
Expand All @@ -906,7 +906,7 @@ m.py:8: error: Need type annotation for 'x'
m.py:9: error: Missing type parameters for generic type

[case testDisallowAnyGenericsCustomGenericClass]
# cmd: mypy m.py
# cmd: mypy --python-version=3.6 m.py
[file mypy.ini]
[[mypy]
[[mypy-m]
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/reports.test
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ Total 0 16 100.00%


[case testAnyExpressionsReportTypesOfAny]
# cmd: mypy --any-exprs-report report n.py
# cmd: mypy --python-version=3.6 --any-exprs-report report n.py

[file n.py]
from typing import Any, List
Expand Down