Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e22887

Browse files
authored
Stop running pytype_test on Python 2-only stubs. (#5904)
pytype is finally dropping Python 2 support (in the upcoming release after 2021.08.03), so pytype_test can no longer run with --python_version=2.
1 parent 32a6257 commit 4e22887

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

tests/pytype_test.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
Depends on pytype being installed.
55
66
If pytype is installed:
7-
1. For every pyi, do nothing if it is in pytype_exclude_list.txt.
7+
1. For every pyi, do nothing if it is in pytype_exclude_list.txt or is
8+
Python 2-only.
89
2. Otherwise, call 'pytype.io.parse_pyi'.
910
Option two will load the file and all the builtins, typeshed dependencies. This
1011
will also discover incorrect usage of imported modules.
@@ -14,7 +15,7 @@
1415
import os
1516
import sys
1617
import traceback
17-
from typing import List, Optional, Sequence, Tuple
18+
from typing import List, Optional, Sequence
1819

1920
from pytype import config as pytype_config, load_pytd
2021
from pytype.pytd import typeshed
@@ -121,7 +122,7 @@ def check_subdirs_discoverable(subdir_paths: List[str]) -> None:
121122
raise SystemExit("Cannot find typeshed subdir at {} (specify parent dir via --typeshed-location)".format(p))
122123

123124

124-
def determine_files_to_test(*, typeshed_location: str, paths: Sequence[str]) -> List[Tuple[str, int]]:
125+
def determine_files_to_test(*, typeshed_location: str, paths: Sequence[str]) -> List[str]:
125126
"""Determine all files to test, checking if it's in the exclude list and which Python versions to use.
126127
127128
Returns a list of pairs of the file path and Python version as an int."""
@@ -134,8 +135,10 @@ def determine_files_to_test(*, typeshed_location: str, paths: Sequence[str]) ->
134135
if rel in skipped:
135136
continue
136137
versions = ts.get_python_major_versions(rel)
137-
if versions:
138-
files.extend((f, v) for v in versions)
138+
if 3 in versions:
139+
files.append(f)
140+
elif versions:
141+
print("Skipping Python 2-only path: {}".format(f))
139142
else:
140143
print("Unrecognized path: {}".format(f))
141144
return files
@@ -152,13 +155,13 @@ def find_stubs_in_paths(paths: Sequence[str]) -> List[str]:
152155
return filenames
153156

154157

155-
def run_all_tests(*, files_to_test: Sequence[Tuple[str, int]], typeshed_location: str, print_stderr: bool, dry_run: bool) -> None:
158+
def run_all_tests(*, files_to_test: Sequence[str], typeshed_location: str, print_stderr: bool, dry_run: bool) -> None:
156159
bad = []
157160
errors = 0
158161
total_tests = len(files_to_test)
159162
print("Testing files with pytype...")
160-
for i, (f, version) in enumerate(files_to_test):
161-
python_version = "2.7" if version == 2 else "{0.major}.{0.minor}".format(sys.version_info)
163+
for i, f in enumerate(files_to_test):
164+
python_version = "{0.major}.{0.minor}".format(sys.version_info)
162165
stderr = (
163166
run_pytype(
164167
filename=f,

0 commit comments

Comments
 (0)