Skip to content

Commit babb1dc

Browse files
authored
Revert "Update "-2" argument to match "--python-version" (#5578)"
This reverts commit 9b9e7e1.
1 parent e5971a2 commit babb1dc

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

mypy/main.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -284,31 +284,27 @@ def infer_python_version_and_executable(options: Options,
284284
This function mutates options based on special_opts to infer the correct Python version and
285285
executable to use.
286286
"""
287-
# Check Options in case python_version is set in a config file, but prefer command
288-
# line arguments.
289-
python_version = special_opts.python_version or options.python_version
290-
291287
# Infer Python version and/or executable if one is not given
292288

293289
# TODO: (ethanhs) Look at folding these checks and the site packages subprocess calls into
294290
# one subprocess call for speed.
295-
if special_opts.python_executable is not None and python_version is not None:
291+
if special_opts.python_executable is not None and special_opts.python_version is not None:
296292
py_exe_ver = _python_version_from_executable(special_opts.python_executable)
297-
if py_exe_ver != python_version:
293+
if py_exe_ver != special_opts.python_version:
298294
raise PythonExecutableInferenceError(
299295
'Python version {} did not match executable {}, got version {}.'.format(
300-
python_version, special_opts.python_executable, py_exe_ver
296+
special_opts.python_version, special_opts.python_executable, py_exe_ver
301297
))
302298
else:
303-
options.python_version = python_version
299+
options.python_version = special_opts.python_version
304300
options.python_executable = special_opts.python_executable
305-
elif special_opts.python_executable is None and python_version is not None:
306-
options.python_version = python_version
301+
elif special_opts.python_executable is None and special_opts.python_version is not None:
302+
options.python_version = special_opts.python_version
307303
py_exe = None
308304
if not special_opts.no_executable:
309-
py_exe = _python_executable_from_version(python_version)
305+
py_exe = _python_executable_from_version(special_opts.python_version)
310306
options.python_executable = py_exe
311-
elif python_version is None and special_opts.python_executable is not None:
307+
elif special_opts.python_version is None and special_opts.python_executable is not None:
312308
options.python_version = _python_version_from_executable(
313309
special_opts.python_executable)
314310
options.python_executable = special_opts.python_executable
@@ -465,7 +461,7 @@ def add_invertible_flag(flag: str,
465461
help='Type check code assuming it will be running on Python x.y',
466462
dest='special-opts:python_version')
467463
platform_group.add_argument(
468-
'-2', '--py2', dest='special-opts:python_version', action='store_const',
464+
'-2', '--py2', dest='python_version', action='store_const',
469465
const=defaults.PYTHON2_VERSION,
470466
help="Use Python 2 mode (same as --python-version 2.7)")
471467
platform_group.add_argument(

mypy/test/testargs.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,6 @@ def test_executable_inference(self) -> None:
6060
assert str(e.value) == 'Python version (2, 10) did not match executable {}, got' \
6161
' version {}.'.format(sys.executable, sys.version_info[:2])
6262

63-
# If a configuration file specifies python_version, it will be set on options.
64-
# Use that to figure out how to determine a value for python_executable, when
65-
# special_opts.python_version is None.
66-
special_opts = argparse.Namespace()
67-
special_opts.python_executable = None
68-
special_opts.python_version = None
69-
special_opts.no_executable = None
70-
options = Options()
71-
options.python_executable = None
72-
options.python_version = sys.version_info[:2]
73-
infer_python_version_and_executable(options, special_opts)
74-
assert options.python_version == sys.version_info[:2]
75-
assert options.python_executable == sys.executable
76-
7763
# test that --no-site-packages will disable executable inference
7864
matching_version = base + ['--python-version={}'.format(sys_ver_str),
7965
'--no-site-packages']

0 commit comments

Comments
 (0)