mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-01-24 20:12:08 +08:00
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 <>
This commit is contained in:
@@ -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
|
||||
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@@ -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
|
||||
|
||||
@@ -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 | \
|
||||
|
||||
@@ -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:
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user