Skip to content

Drop Python 3.2 support. #3244

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 3 commits into from
Apr 27, 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
26 changes: 20 additions & 6 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,22 @@ def __getattr__(self, name: str) -> Any:

def parse_version(v: str) -> Tuple[int, int]:
m = re.match(r'\A(\d)\.(\d+)\Z', v)
if m:
return int(m.group(1)), int(m.group(2))
else:
if not m:
raise argparse.ArgumentTypeError(
"Invalid python version '{}' (expected format: 'x.y')".format(v))
major, minor = int(m.group(1)), int(m.group(2))
if major == 2:
if minor != 7:
raise argparse.ArgumentTypeError(
"Python 2.{} is not supported (must be 2.7)".format(minor))
elif major == 3:
if minor <= 2:
raise argparse.ArgumentTypeError(
"Python 3.{} is not supported (must be 3.3 or higher)".format(minor))
else:
raise argparse.ArgumentTypeError(
"Python major version '{}' out of range (must be 2 or 3)".format(major))
return major, minor


# Make the help output a little less jarring.
Expand Down Expand Up @@ -553,8 +564,7 @@ def get_init_file(dir: str) -> Optional[str]:
# exists to specify types for values initialized to None or container
# types.
config_types = {
# TODO: Check validity of python version
'python_version': lambda s: tuple(map(int, s.split('.'))),
'python_version': parse_version,
'strict_optional_whitelist': lambda s: s.split(),
'custom_typing_module': str,
'custom_typeshed_dir': str,
Expand Down Expand Up @@ -663,7 +673,11 @@ def parse_section(prefix: str, template: Options,
if ct is bool:
v = section.getboolean(key) # type: ignore # Until better stub
elif callable(ct):
v = ct(section.get(key))
try:
v = ct(section.get(key))
except argparse.ArgumentTypeError as err:
print("%s: %s: %s" % (prefix, key, err), file=sys.stderr)
continue
else:
print("%s: Don't know what type %s should have" % (prefix, key), file=sys.stderr)
continue
Expand Down
2 changes: 1 addition & 1 deletion mypy/test/testcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import Dict, List, Optional, Set, Tuple

from mypy import build, defaults
from mypy.main import parse_version, process_options
from mypy.main import process_options
from mypy.build import BuildSource, find_module_clear_caches
from mypy.myunit import AssertionFailure
from mypy.test.config import test_temp_dir, test_data_prefix
Expand Down
8 changes: 4 additions & 4 deletions test-data/unit/check-unreachable-code.test
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,9 @@ x = 1
[out]

[case testCustomSysVersionInfo]
# flags: --python-version 3.2
# flags: --python-version 3.5
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it easy to add test cases for this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

I could add testcases to test-data/unit/cmdline.test like this:

[case testPython2VersionTooOld]
# cmd: mypy --python-version 2.6 -c pass
[out]
...

But a problem with that is that the output includes the full usage message, e.g.

  usage: mypy [-h] [-v] [-V] [--python-version x.y] [--platform PLATFORM] [-2] [--ignore-missing-imports] [--follow-imports {normal,silent,skip,error}] (diff)
              [--disallow-untyped-calls] [--disallow-untyped-defs] [--check-untyped-defs] [--disallow-subclassing-any] [--warn-incomplete-stub] [--warn-redundant-casts] (diff)
              [--no-warn-no-return] [--warn-return-any] [--warn-unused-ignores] [--show-error-context] [-i] [--quick-and-dirty] [--cache-dir DIR] [--strict-optional] (diff)
              [--strict-optional-whitelist [GLOB [GLOB ...]]] [--junit-xml JUNIT_XML] [--pdb] [--show-traceback] [--stats] [--inferstats] [--custom-typing MODULE] (diff)
              [--custom-typeshed-dir DIR] [--scripts-are-modules] [--config-file CONFIG_FILE] [--show-column-numbers] [--find-occurrences CLASS.MEMBER] [--strict] (diff)
              [--strict-boolean] [--cobertura-xml-report DIR] [--html-report DIR] [--linecount-report DIR] [--linecoverage-report DIR] [--memory-xml-report DIR] (diff)
              [--old-html-report DIR] [--txt-report DIR] [--xml-report DIR] [--xslt-html-report DIR] [--xslt-txt-report DIR] [-m MODULE] [-c PROGRAM_TEXT] [-p PACKAGE] (diff)
              [files [files ...]]               (diff)
  mypy: error: argument --python-version: Python 2.8 is not supported (must be 2.7) (diff)

which requires updating the tests frequently because the usage message changes each time we add a new flag.

Not sure I like tinkering with this more.

import sys
if sys.version_info == (3, 2):
if sys.version_info == (3, 5):
x = "foo"
else:
x = 3
Expand All @@ -415,9 +415,9 @@ reveal_type(x) # E: Revealed type is 'builtins.str'
[out]

[case testCustomSysVersionInfo2]
# flags: --python-version 3.1
# flags: --python-version 3.5
import sys
if sys.version_info == (3, 2):
if sys.version_info == (3, 6):
x = "foo"
else:
x = 3
Expand Down
61 changes: 61 additions & 0 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,64 @@ whatever
main.py:1: error: Cannot find module named 'a'
main.py:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
main.py:1: error: Cannot find module named 'a.b'

[case testPythonVersionTooOld10]
# cmd: mypy -c pass
[file mypy.ini]
[[mypy]
python_version = 1.0
[out]
mypy.ini: [mypy]: python_version: Python major version '1' out of range (must be 2 or 3)

[case testPythonVersionTooOld26]
# cmd: mypy -c pass
[file mypy.ini]
[[mypy]
python_version = 2.6
[out]
mypy.ini: [mypy]: python_version: Python 2.6 is not supported (must be 2.7)

[case testPythonVersionTooOld32]
# cmd: mypy -c pass
[file mypy.ini]
[[mypy]
python_version = 3.2
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like there's no test that checks that 3.3 is still accepted? We only have a test that checks that 3.2 is rejected.

[out]
mypy.ini: [mypy]: python_version: Python 3.2 is not supported (must be 3.3 or higher)

[case testPythonVersionTooNew28]
# cmd: mypy -c pass
[file mypy.ini]
[[mypy]
python_version = 2.8
[out]
mypy.ini: [mypy]: python_version: Python 2.8 is not supported (must be 2.7)

[case testPythonVersionTooNew40]
# cmd: mypy -c pass
[file mypy.ini]
[[mypy]
python_version = 4.0
[out]
mypy.ini: [mypy]: python_version: Python major version '4' out of range (must be 2 or 3)

[case testPythonVersionAccepted27]
# cmd: mypy -c pass
[file mypy.ini]
[[mypy]
python_version = 2.7
[out]

[case testPythonVersionAccepted33]
# cmd: mypy -c pass
[file mypy.ini]
[[mypy]
python_version = 3.3
[out]

[case testPythonVersionAccepted36]
# cmd: mypy -c pass
[file mypy.ini]
[[mypy]
python_version = 3.6
[out]