Skip to content

Commit 5c5b184

Browse files
committed
Require typing module before using a Py2 interpreter for tests.
Tested with: a) Python 2.7 interpreter on PATH without typing installed: Py2 subprocess tests skipped. b) Python 2.7 interpreter on PATH with typing installed: Py2 subprocess tests pass. c) Temporarily change assertion to require `(2, 6)` instead of `(2, 7)`, with no Python2.6 interpreter available (to verify that version assert works correctly): Py2 subprocess tests skipped.
1 parent eec6745 commit 5c5b184

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

mypy/util.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ def try_find_python2_interpreter() -> Optional[str]:
6969
return _python2_interpreter
7070
for interpreter in default_python2_interpreter:
7171
try:
72-
process = subprocess.Popen([interpreter, '-V'], stdout=subprocess.PIPE,
73-
stderr=subprocess.STDOUT)
74-
stdout, stderr = process.communicate()
75-
if b'Python 2.7' in stdout:
72+
retcode = subprocess.Popen([
73+
interpreter, '-c',
74+
'import sys, typing; assert sys.version_info[:2] == (2, 7)'
75+
]).wait()
76+
if not retcode:
7677
_python2_interpreter = interpreter
7778
return interpreter
7879
except OSError:

0 commit comments

Comments
 (0)