@@ -284,31 +284,27 @@ def infer_python_version_and_executable(options: Options,
284
284
This function mutates options based on special_opts to infer the correct Python version and
285
285
executable to use.
286
286
"""
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
-
291
287
# Infer Python version and/or executable if one is not given
292
288
293
289
# TODO: (ethanhs) Look at folding these checks and the site packages subprocess calls into
294
290
# 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 :
296
292
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 :
298
294
raise PythonExecutableInferenceError (
299
295
'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
301
297
))
302
298
else :
303
- options .python_version = python_version
299
+ options .python_version = special_opts . python_version
304
300
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
307
303
py_exe = None
308
304
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 )
310
306
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 :
312
308
options .python_version = _python_version_from_executable (
313
309
special_opts .python_executable )
314
310
options .python_executable = special_opts .python_executable
@@ -465,7 +461,7 @@ def add_invertible_flag(flag: str,
465
461
help = 'Type check code assuming it will be running on Python x.y' ,
466
462
dest = 'special-opts:python_version' )
467
463
platform_group .add_argument (
468
- '-2' , '--py2' , dest = 'special-opts: python_version' , action = 'store_const' ,
464
+ '-2' , '--py2' , dest = 'python_version' , action = 'store_const' ,
469
465
const = defaults .PYTHON2_VERSION ,
470
466
help = "Use Python 2 mode (same as --python-version 2.7)" )
471
467
platform_group .add_argument (
0 commit comments