From 274f449edce829201ef63da2e566497b28d3d97c Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Tue, 16 May 2023 15:38:49 -0700 Subject: [PATCH] Treat entries on pytype_exclude_list as missing modules for pytype_test. (#10187) --- tests/pytype_test.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/pytype_test.py b/tests/pytype_test.py index 4d7a1f888..2b3265497 100755 --- a/tests/pytype_test.py +++ b/tests/pytype_test.py @@ -142,11 +142,14 @@ def find_stubs_in_paths(paths: Sequence[str]) -> list[str]: def get_missing_modules(files_to_test: Sequence[str]) -> Iterable[str]: - """Gets module names provided by typeshed-external dependencies. + """Get names of modules that should be treated as missing. Some typeshed stubs depend on dependencies outside of typeshed. Since pytype isn't able to read such dependencies, we instead declare them as "missing" modules, so that no errors are reported for them. + + Similarly, pytype cannot parse files on its exclude list, so we also treat + those as missing. """ stub_distributions = set() for fi in files_to_test: @@ -165,6 +168,17 @@ def get_missing_modules(files_to_test: Sequence[str]) -> Iterable[str]: top_level_file = os.path.join(egg_info, "top_level.txt") with open(top_level_file) as f: missing_modules.update(f.read().splitlines()) + test_dir = os.path.dirname(__file__) + exclude_list = os.path.join(test_dir, "pytype_exclude_list.txt") + with open(exclude_list) as f: + excluded_files = f.readlines() + for fi in excluded_files: + if not fi.startswith("stubs/"): + # Skips comments, empty lines, and stdlib files, which are in + # the exclude list because pytype has its own version. + continue + unused_stubs_prefix, unused_pkg, mod_path = fi.split("/", 2) # pyright: ignore [reportUnusedVariable] + missing_modules.add(os.path.splitext(mod_path)[0]) return missing_modules