Skip to content

Commit 274f449

Browse files
authored
Treat entries on pytype_exclude_list as missing modules for pytype_test. (#10187)
1 parent f143f47 commit 274f449

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tests/pytype_test.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,14 @@ def find_stubs_in_paths(paths: Sequence[str]) -> list[str]:
142142

143143

144144
def get_missing_modules(files_to_test: Sequence[str]) -> Iterable[str]:
145-
"""Gets module names provided by typeshed-external dependencies.
145+
"""Get names of modules that should be treated as missing.
146146
147147
Some typeshed stubs depend on dependencies outside of typeshed. Since pytype
148148
isn't able to read such dependencies, we instead declare them as "missing"
149149
modules, so that no errors are reported for them.
150+
151+
Similarly, pytype cannot parse files on its exclude list, so we also treat
152+
those as missing.
150153
"""
151154
stub_distributions = set()
152155
for fi in files_to_test:
@@ -165,6 +168,17 @@ def get_missing_modules(files_to_test: Sequence[str]) -> Iterable[str]:
165168
top_level_file = os.path.join(egg_info, "top_level.txt")
166169
with open(top_level_file) as f:
167170
missing_modules.update(f.read().splitlines())
171+
test_dir = os.path.dirname(__file__)
172+
exclude_list = os.path.join(test_dir, "pytype_exclude_list.txt")
173+
with open(exclude_list) as f:
174+
excluded_files = f.readlines()
175+
for fi in excluded_files:
176+
if not fi.startswith("stubs/"):
177+
# Skips comments, empty lines, and stdlib files, which are in
178+
# the exclude list because pytype has its own version.
179+
continue
180+
unused_stubs_prefix, unused_pkg, mod_path = fi.split("/", 2) # pyright: ignore [reportUnusedVariable]
181+
missing_modules.add(os.path.splitext(mod_path)[0])
168182
return missing_modules
169183

170184

0 commit comments

Comments
 (0)