From e66ceceed0d2ffde8d1c718075fe38889643a92c Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Thu, 10 Jun 2021 14:33:44 -0700 Subject: [PATCH] Rename whitelist to allowlist (#5614) Resolves #4436 I want to add stubtest for third party stubs, and figured it'd be easier to make this change now. Co-authored-by: hauntsaninja <> --- ...list.yml => stubtest-unused-allowlist.yml} | 10 +++--- .github/workflows/tests.yml | 2 +- scripts/generate_proto_stubs.sh | 2 +- ...telist.py => update-stubtest-allowlist.py} | 10 +++--- tests/README.md | 4 +-- .../darwin-py310.txt | 0 .../darwin-py36.txt | 0 .../darwin-py37.txt | 0 .../darwin-py38.txt | 0 .../darwin-py39.txt | 0 .../darwin.txt | 2 +- .../linux-py310.txt | 0 .../linux-py36.txt | 0 .../linux-py37.txt | 0 .../linux-py38.txt | 0 .../linux-py39.txt | 0 .../linux.txt | 2 +- .../py310.txt | 0 .../py36.txt | 0 .../py37.txt | 0 .../py38.txt | 0 .../py39.txt | 0 .../py3_common.txt | 2 +- .../win32-py310.txt | 0 .../win32-py36.txt | 0 .../win32-py37.txt | 0 .../win32-py38.txt | 0 .../win32.txt | 2 +- tests/stubtest_test.py | 36 +++++++++---------- tests/stubtest_unused.py | 8 ++--- 30 files changed, 40 insertions(+), 40 deletions(-) rename .github/workflows/{stubtest-unused-whitelist.yml => stubtest-unused-allowlist.yml} (85%) rename scripts/{update-stubtest-whitelist.py => update-stubtest-allowlist.py} (82%) rename tests/{stubtest_whitelists => stubtest_allowlists}/darwin-py310.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/darwin-py36.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/darwin-py37.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/darwin-py38.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/darwin-py39.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/darwin.txt (96%) rename tests/{stubtest_whitelists => stubtest_allowlists}/linux-py310.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/linux-py36.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/linux-py37.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/linux-py38.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/linux-py39.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/linux.txt (96%) rename tests/{stubtest_whitelists => stubtest_allowlists}/py310.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/py36.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/py37.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/py38.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/py39.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/py3_common.txt (99%) rename tests/{stubtest_whitelists => stubtest_allowlists}/win32-py310.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/win32-py36.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/win32-py37.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/win32-py38.txt (100%) rename tests/{stubtest_whitelists => stubtest_allowlists}/win32.txt (91%) diff --git a/.github/workflows/stubtest-unused-whitelist.yml b/.github/workflows/stubtest-unused-allowlist.yml similarity index 85% rename from .github/workflows/stubtest-unused-whitelist.yml rename to .github/workflows/stubtest-unused-allowlist.yml index b83cb6efc..6a07fd819 100644 --- a/.github/workflows/stubtest-unused-whitelist.yml +++ b/.github/workflows/stubtest-unused-allowlist.yml @@ -1,4 +1,4 @@ -name: Remove unused stubtest whitelist entries +name: Remove unused stubtest allowlist entries on: workflow_dispatch: @@ -49,13 +49,13 @@ jobs: name: stubtest-output - name: Collate duplicates run: cat stubtest-output-* | sort -u | tee stubtest-output - - name: Remove entries from whitelists - run: python scripts/update-stubtest-whitelist.py stubtest-output + - name: Remove entries from allowlists + run: python scripts/update-stubtest-allowlist.py stubtest-output - name: Create pull request # v3.8.2 uses: peter-evans/create-pull-request@052fc72b4198ba9fbc81b818c6e1859f747d49a8 with: token: ${{ secrets.GITHUB_TOKEN }} - commit-message: Remove unused stubtest whitelist entries - title: "[gh-action] Remove unused stubtest whitelist entries" + commit-message: Remove unused stubtest allowlist entries + title: "[gh-action] Remove unused stubtest allowlist entries" base: master diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8ba682c0b..7789f6079 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -112,4 +112,4 @@ jobs: - name: Install dependencies run: pip install $(grep mypy== requirements-tests-py3.txt) - name: Run stubtest - run: python tests/stubtest_test.py --ignore-unused-whitelist + run: python tests/stubtest_test.py --ignore-unused-allowlist diff --git a/scripts/generate_proto_stubs.sh b/scripts/generate_proto_stubs.sh index ce97a166c..fb49cd538 100755 --- a/scripts/generate_proto_stubs.sh +++ b/scripts/generate_proto_stubs.sh @@ -53,7 +53,7 @@ find $REPO_ROOT/stubs/protobuf/ -name "*_pb2.pyi" -delete # Roughly reproduce the subset of .proto files on the public interface as described # by find_package_modules in the protobuf setup.py. -# The logic (as of 3.14.0) can roughly be described as a whitelist of .proto files +# The logic (as of 3.14.0) can roughly be described as a allowlist of .proto files # further limited to exclude *test* and internal/ # https://github.com/protocolbuffers/protobuf/blob/master/python/setup.py PROTO_FILES=$(grep "generate_proto.*google" $PYTHON_PROTOBUF_DIR/python/setup.py | \ diff --git a/scripts/update-stubtest-whitelist.py b/scripts/update-stubtest-allowlist.py similarity index 82% rename from scripts/update-stubtest-whitelist.py rename to scripts/update-stubtest-allowlist.py index c8b1fcb8a..0d9c44e6c 100755 --- a/scripts/update-stubtest-whitelist.py +++ b/scripts/update-stubtest-allowlist.py @@ -1,11 +1,11 @@ #!/usr/bin/env python3 -# This script removes lines from stubtest whitelists, according to +# This script removes lines from stubtest allowlists, according to # an input file. The input file has one entry to remove per line. -# Each line consists of a whitelist filename and an entry, separated +# Each line consists of a allowlist filename and an entry, separated # by a colon. -# This script is used by the workflow to remove unused whitelist entries. +# This script is used by the workflow to remove unused allowlist entries. import sys from collections import defaultdict @@ -19,7 +19,7 @@ def main() -> None: to_remove = parse_input_file(sys.argv[1]) for filename, entries in to_remove.items(): - remove_entries_from_whitelist(filename, entries) + remove_entries_from_allowlist(filename, entries) def parse_input_file(input_file: str) -> Dict[str, Set[str]]: @@ -37,7 +37,7 @@ def parse_input_line(line: str) -> Tuple[str, str]: return filename, entry -def remove_entries_from_whitelist(filename: str, entries: Set[str]) -> None: +def remove_entries_from_allowlist(filename: str, entries: Set[str]) -> None: new_lines: List[str] = [] with open(filename) as f: for line in f: diff --git a/tests/README.md b/tests/README.md index a7453ae3a..457e3972b 100644 --- a/tests/README.md +++ b/tests/README.md @@ -81,8 +81,8 @@ If you need a specific version of Python to repro a CI failure, [pyenv](https://github.com/pyenv/pyenv) can help. Due to its dynamic nature, you may run into false positives. In this case, you -can add to the whitelists for each affected Python version in -`tests/stubtest_whitelists`. Please file issues for stubtest false positives +can add to the allowlists for each affected Python version in +`tests/stubtest_allowlists`. Please file issues for stubtest false positives at [mypy](https://github.com/python/mypy/issues). To run stubtest against third party stubs, it's easiest to use stubtest diff --git a/tests/stubtest_whitelists/darwin-py310.txt b/tests/stubtest_allowlists/darwin-py310.txt similarity index 100% rename from tests/stubtest_whitelists/darwin-py310.txt rename to tests/stubtest_allowlists/darwin-py310.txt diff --git a/tests/stubtest_whitelists/darwin-py36.txt b/tests/stubtest_allowlists/darwin-py36.txt similarity index 100% rename from tests/stubtest_whitelists/darwin-py36.txt rename to tests/stubtest_allowlists/darwin-py36.txt diff --git a/tests/stubtest_whitelists/darwin-py37.txt b/tests/stubtest_allowlists/darwin-py37.txt similarity index 100% rename from tests/stubtest_whitelists/darwin-py37.txt rename to tests/stubtest_allowlists/darwin-py37.txt diff --git a/tests/stubtest_whitelists/darwin-py38.txt b/tests/stubtest_allowlists/darwin-py38.txt similarity index 100% rename from tests/stubtest_whitelists/darwin-py38.txt rename to tests/stubtest_allowlists/darwin-py38.txt diff --git a/tests/stubtest_whitelists/darwin-py39.txt b/tests/stubtest_allowlists/darwin-py39.txt similarity index 100% rename from tests/stubtest_whitelists/darwin-py39.txt rename to tests/stubtest_allowlists/darwin-py39.txt diff --git a/tests/stubtest_whitelists/darwin.txt b/tests/stubtest_allowlists/darwin.txt similarity index 96% rename from tests/stubtest_whitelists/darwin.txt rename to tests/stubtest_allowlists/darwin.txt index cb6f25fec..43c03a7c8 100644 --- a/tests/stubtest_whitelists/darwin.txt +++ b/tests/stubtest_allowlists/darwin.txt @@ -21,7 +21,7 @@ select.kqueue.__init__ # default C signature is wrong select.POLLMSG # system dependent # ========== -# Whitelist entries that cannot or should not be fixed +# Allowlist entries that cannot or should not be fixed # ========== # Modules that do not exist on macos systems diff --git a/tests/stubtest_whitelists/linux-py310.txt b/tests/stubtest_allowlists/linux-py310.txt similarity index 100% rename from tests/stubtest_whitelists/linux-py310.txt rename to tests/stubtest_allowlists/linux-py310.txt diff --git a/tests/stubtest_whitelists/linux-py36.txt b/tests/stubtest_allowlists/linux-py36.txt similarity index 100% rename from tests/stubtest_whitelists/linux-py36.txt rename to tests/stubtest_allowlists/linux-py36.txt diff --git a/tests/stubtest_whitelists/linux-py37.txt b/tests/stubtest_allowlists/linux-py37.txt similarity index 100% rename from tests/stubtest_whitelists/linux-py37.txt rename to tests/stubtest_allowlists/linux-py37.txt diff --git a/tests/stubtest_whitelists/linux-py38.txt b/tests/stubtest_allowlists/linux-py38.txt similarity index 100% rename from tests/stubtest_whitelists/linux-py38.txt rename to tests/stubtest_allowlists/linux-py38.txt diff --git a/tests/stubtest_whitelists/linux-py39.txt b/tests/stubtest_allowlists/linux-py39.txt similarity index 100% rename from tests/stubtest_whitelists/linux-py39.txt rename to tests/stubtest_allowlists/linux-py39.txt diff --git a/tests/stubtest_whitelists/linux.txt b/tests/stubtest_allowlists/linux.txt similarity index 96% rename from tests/stubtest_whitelists/linux.txt rename to tests/stubtest_allowlists/linux.txt index febf363b7..36fcfe49b 100644 --- a/tests/stubtest_whitelists/linux.txt +++ b/tests/stubtest_allowlists/linux.txt @@ -26,7 +26,7 @@ spwd.struct_spwd._make # PyStructSequence spwd.struct_spwd._replace # PyStructSequence # ========== -# Whitelist entries that cannot or should not be fixed +# Allowlist entries that cannot or should not be fixed # ========== # Modules that do not exist on Linux systems diff --git a/tests/stubtest_whitelists/py310.txt b/tests/stubtest_allowlists/py310.txt similarity index 100% rename from tests/stubtest_whitelists/py310.txt rename to tests/stubtest_allowlists/py310.txt diff --git a/tests/stubtest_whitelists/py36.txt b/tests/stubtest_allowlists/py36.txt similarity index 100% rename from tests/stubtest_whitelists/py36.txt rename to tests/stubtest_allowlists/py36.txt diff --git a/tests/stubtest_whitelists/py37.txt b/tests/stubtest_allowlists/py37.txt similarity index 100% rename from tests/stubtest_whitelists/py37.txt rename to tests/stubtest_allowlists/py37.txt diff --git a/tests/stubtest_whitelists/py38.txt b/tests/stubtest_allowlists/py38.txt similarity index 100% rename from tests/stubtest_whitelists/py38.txt rename to tests/stubtest_allowlists/py38.txt diff --git a/tests/stubtest_whitelists/py39.txt b/tests/stubtest_allowlists/py39.txt similarity index 100% rename from tests/stubtest_whitelists/py39.txt rename to tests/stubtest_allowlists/py39.txt diff --git a/tests/stubtest_whitelists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt similarity index 99% rename from tests/stubtest_whitelists/py3_common.txt rename to tests/stubtest_allowlists/py3_common.txt index c7ea6aa95..7e66b97e6 100644 --- a/tests/stubtest_whitelists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -219,7 +219,7 @@ webbrowser.UnixBrowser.remote_action_newwin # always overridden in inheriting c wsgiref.types # Doesn't exist, see comments in file # ========== -# Whitelist entries that cannot or should not be fixed +# Allowlist entries that cannot or should not be fixed # ========== _pydecimal.* # See comments in file ast.NodeVisitor.visit_\w+ # Methods are discovered dynamically, see #3796 diff --git a/tests/stubtest_whitelists/win32-py310.txt b/tests/stubtest_allowlists/win32-py310.txt similarity index 100% rename from tests/stubtest_whitelists/win32-py310.txt rename to tests/stubtest_allowlists/win32-py310.txt diff --git a/tests/stubtest_whitelists/win32-py36.txt b/tests/stubtest_allowlists/win32-py36.txt similarity index 100% rename from tests/stubtest_whitelists/win32-py36.txt rename to tests/stubtest_allowlists/win32-py36.txt diff --git a/tests/stubtest_whitelists/win32-py37.txt b/tests/stubtest_allowlists/win32-py37.txt similarity index 100% rename from tests/stubtest_whitelists/win32-py37.txt rename to tests/stubtest_allowlists/win32-py37.txt diff --git a/tests/stubtest_whitelists/win32-py38.txt b/tests/stubtest_allowlists/win32-py38.txt similarity index 100% rename from tests/stubtest_whitelists/win32-py38.txt rename to tests/stubtest_allowlists/win32-py38.txt diff --git a/tests/stubtest_whitelists/win32.txt b/tests/stubtest_allowlists/win32.txt similarity index 91% rename from tests/stubtest_whitelists/win32.txt rename to tests/stubtest_allowlists/win32.txt index 8ced5d710..a1f86930b 100644 --- a/tests/stubtest_whitelists/win32.txt +++ b/tests/stubtest_allowlists/win32.txt @@ -6,7 +6,7 @@ locale.[A-Z0-9_]+ # Constants that should be moved to _locale and re-exported c locale.nl_langinfo # Function that should be moved to _locale and re-exported conditionally # ========== -# Whitelist entries that cannot or should not be fixed +# Allowlist entries that cannot or should not be fixed # ========== # Modules that do not exist on Windows systems diff --git a/tests/stubtest_test.py b/tests/stubtest_test.py index b3ba3b78c..1d40b1a2d 100755 --- a/tests/stubtest_test.py +++ b/tests/stubtest_test.py @@ -16,40 +16,40 @@ from pathlib import Path def run_stubtest(typeshed_dir: Path) -> int: - whitelist_dir = typeshed_dir / "tests" / "stubtest_whitelists" - version_whitelist = "py{}{}.txt".format(sys.version_info.major, sys.version_info.minor) - platform_whitelist = "{}.txt".format(sys.platform) - combined_whitelist = "{}-py{}{}.txt".format(sys.platform, sys.version_info.major, sys.version_info.minor) + allowlist_dir = typeshed_dir / "tests" / "stubtest_allowlists" + version_allowlist = "py{}{}.txt".format(sys.version_info.major, sys.version_info.minor) + platform_allowlist = "{}.txt".format(sys.platform) + combined_allowlist = "{}-py{}{}.txt".format(sys.platform, sys.version_info.major, sys.version_info.minor) - ignore_unused_whitelist = "--ignore-unused-whitelist" in sys.argv[1:] + ignore_unused_allowlist = "--ignore-unused-allowlist" in sys.argv[1:] cmd = [ sys.executable, "-m", "mypy.stubtest", # Use --ignore-missing-stub, because if someone makes a correct addition, they'll need to - # also make a whitelist change and if someone makes an incorrect addition, they'll run into + # also make a allowlist change and if someone makes an incorrect addition, they'll run into # false negatives. "--ignore-missing-stub", "--check-typeshed", "--custom-typeshed-dir", str(typeshed_dir), - "--whitelist", - str(whitelist_dir / "py3_common.txt"), - "--whitelist", - str(whitelist_dir / version_whitelist), + "--allowlist", + str(allowlist_dir / "py3_common.txt"), + "--allowlist", + str(allowlist_dir / version_allowlist), ] - if ignore_unused_whitelist: - cmd += ["--ignore-unused-whitelist"] - if (whitelist_dir / platform_whitelist).exists(): + if ignore_unused_allowlist: + cmd += ["--ignore-unused-allowlist"] + if (allowlist_dir / platform_allowlist).exists(): cmd += [ - "--whitelist", - str(whitelist_dir / platform_whitelist), + "--allowlist", + str(allowlist_dir / platform_allowlist), ] - if (whitelist_dir / combined_whitelist).exists(): + if (allowlist_dir / combined_allowlist).exists(): cmd += [ - "--whitelist", - str(whitelist_dir / combined_whitelist), + "--allowlist", + str(allowlist_dir / combined_allowlist), ] if sys.version_info < (3, 10): # As discussed in https://github.com/python/typeshed/issues/3693, we only aim for diff --git a/tests/stubtest_unused.py b/tests/stubtest_unused.py index e0a8ed10d..32a06b2a4 100755 --- a/tests/stubtest_unused.py +++ b/tests/stubtest_unused.py @@ -1,13 +1,13 @@ #!/usr/bin/env python3 -# Runs stubtest and prints each unused whitelist entry with filename. +# Runs stubtest and prints each unused allowlist entry with filename. import subprocess import sys from pathlib import Path from typing import List, Tuple _UNUSED_NOTE = "note: unused allowlist entry " -_WHITELIST_PATH = Path("tests") / "stubtest_whitelists" +_ALLOWLIST_PATH = Path("tests") / "stubtest_allowlists" def main() -> None: @@ -30,11 +30,11 @@ 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 = _WHITELIST_PATH / file + path = _ALLOWLIST_PATH / file if find_unused_in_file(unused, path): found.append((path.as_posix(), unused)) if not found: - raise ValueError("unused item {} not found in any whitelist file".format(unused)) + raise ValueError("unused item {} not found in any allowlist file".format(unused)) return found