From 5e6fb40b561ebe9b1dc7b63e6ec47200019bd575 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Mon, 10 May 2021 23:24:37 -0700 Subject: [PATCH] Fix stubtest unused script (#5411) Contrary to the comment, this wasn't a mypy_primer issue, nor even a stubtest issue. Co-authored-by: hauntsaninja <> --- .github/workflows/stubtest-unused-whitelist.yml | 3 --- tests/stubtest_unused.py | 11 +++++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/.github/workflows/stubtest-unused-whitelist.yml b/.github/workflows/stubtest-unused-whitelist.yml index c342f48c1..a7a0579eb 100644 --- a/.github/workflows/stubtest-unused-whitelist.yml +++ b/.github/workflows/stubtest-unused-whitelist.yml @@ -50,9 +50,6 @@ jobs: uses: actions/download-artifact@v2 with: name: stubtest-output - # TODO: maybe mypy_primer should always output forward slashes - - name: Fix slashes - run: sed -i 's:\\:/:g' stubtest-output-windows-* - name: Collate duplicates run: cat stubtest-output-* | sort -u | tee stubtest-output - name: Remove entries from whitelists diff --git a/tests/stubtest_unused.py b/tests/stubtest_unused.py index 916806579..e0a8ed10d 100755 --- a/tests/stubtest_unused.py +++ b/tests/stubtest_unused.py @@ -1,14 +1,13 @@ #!/usr/bin/env python3 # Runs stubtest and prints each unused whitelist entry with filename. - -import os.path import subprocess import sys +from pathlib import Path from typing import List, Tuple _UNUSED_NOTE = "note: unused allowlist entry " -_WHITELIST_PATH = os.path.join("tests", "stubtest_whitelists") +_WHITELIST_PATH = Path("tests") / "stubtest_whitelists" def main() -> None: @@ -31,15 +30,15 @@ def unused_files(unused: str) -> List[Tuple[str, str]]: files = ["py3_common.txt", version + ".txt", sys.platform + ".txt", sys.platform + "-" + version + ".txt"] found = [] for file in files: - path = os.path.join(_WHITELIST_PATH, file) + path = _WHITELIST_PATH / file if find_unused_in_file(unused, path): - found.append((path, unused)) + found.append((path.as_posix(), unused)) if not found: raise ValueError("unused item {} not found in any whitelist file".format(unused)) return found -def find_unused_in_file(unused: str, path: str) -> bool: +def find_unused_in_file(unused: str, path: Path) -> bool: try: with open(path) as f: return any(line.strip().split(" ")[0] == unused for line in f)