mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 20:54:28 +08:00
Bump protobuf to 4.21.*; delete google/__init__.pyi (#8360)
This major version bump of the stubs package deletes google/__init__.py, which does not exist at runtime, and caused problems for several users. Mypy now has --namespace-packages enabled by default, which should hopefully mean that this causes minimal pain. Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
committed by
GitHub
parent
21f26ab4f3
commit
5453c97753
@@ -32,6 +32,12 @@ from utils import (
|
||||
strip_comments,
|
||||
)
|
||||
|
||||
try:
|
||||
from mypy.api import run as mypy_run
|
||||
except ImportError:
|
||||
print_error("Cannot import mypy. Did you install it?")
|
||||
sys.exit(1)
|
||||
|
||||
SUPPORTED_VERSIONS = ["3.11", "3.10", "3.9", "3.8", "3.7"]
|
||||
SUPPORTED_PLATFORMS = ("linux", "win32", "darwin")
|
||||
DIRECTORIES_TO_TEST = [Path("stdlib"), Path("stubs")]
|
||||
@@ -198,13 +204,7 @@ def add_configuration(configurations: list[MypyDistConf], distribution: str) ->
|
||||
configurations.append(MypyDistConf(module_name, values.copy()))
|
||||
|
||||
|
||||
def run_mypy(args: TestConfig, configurations: list[MypyDistConf], files: list[Path]) -> ReturnCode:
|
||||
try:
|
||||
from mypy.api import run as mypy_run
|
||||
except ImportError:
|
||||
print_error("Cannot import mypy. Did you install it?")
|
||||
sys.exit(1)
|
||||
|
||||
def run_mypy(args: TestConfig, configurations: list[MypyDistConf], files: list[Path], *, testing_stdlib: bool) -> ReturnCode:
|
||||
with tempfile.NamedTemporaryFile("w+") as temp:
|
||||
temp.write("[mypy]\n")
|
||||
for dist_conf in configurations:
|
||||
@@ -213,7 +213,7 @@ def run_mypy(args: TestConfig, configurations: list[MypyDistConf], files: list[P
|
||||
temp.write(f"{k} = {v}\n")
|
||||
temp.flush()
|
||||
|
||||
flags = get_mypy_flags(args, temp.name)
|
||||
flags = get_mypy_flags(args, temp.name, testing_stdlib=testing_stdlib)
|
||||
mypy_args = [*flags, *map(str, files)]
|
||||
if args.verbose:
|
||||
print("running mypy", " ".join(mypy_args))
|
||||
@@ -238,8 +238,8 @@ def run_mypy(args: TestConfig, configurations: list[MypyDistConf], files: list[P
|
||||
return exit_code
|
||||
|
||||
|
||||
def get_mypy_flags(args: TestConfig, temp_name: str) -> list[str]:
|
||||
return [
|
||||
def get_mypy_flags(args: TestConfig, temp_name: str, *, testing_stdlib: bool) -> list[str]:
|
||||
flags = [
|
||||
"--python-version",
|
||||
args.version,
|
||||
"--show-traceback",
|
||||
@@ -260,6 +260,9 @@ def get_mypy_flags(args: TestConfig, temp_name: str) -> list[str]:
|
||||
"--config-file",
|
||||
temp_name,
|
||||
]
|
||||
if not testing_stdlib:
|
||||
flags.append("--explicit-package-bases")
|
||||
return flags
|
||||
|
||||
|
||||
def add_third_party_files(
|
||||
@@ -315,7 +318,14 @@ def test_third_party_distribution(distribution: str, args: TestConfig) -> TestRe
|
||||
print_error("no files found")
|
||||
sys.exit(1)
|
||||
|
||||
code = run_mypy(args, configurations, files)
|
||||
prev_mypypath = os.getenv("MYPYPATH")
|
||||
os.environ["MYPYPATH"] = os.pathsep.join(str(Path("stubs", dist)) for dist in seen_dists)
|
||||
code = run_mypy(args, configurations, files, testing_stdlib=False)
|
||||
if prev_mypypath is None:
|
||||
del os.environ["MYPYPATH"]
|
||||
else:
|
||||
os.environ["MYPYPATH"] = prev_mypypath
|
||||
|
||||
return TestResults(code, len(files))
|
||||
|
||||
|
||||
@@ -333,8 +343,8 @@ def test_stdlib(code: int, args: TestConfig) -> TestResults:
|
||||
|
||||
if files:
|
||||
print(f"Testing stdlib ({len(files)} files)...")
|
||||
print("Running mypy " + " ".join(get_mypy_flags(args, "/tmp/...")))
|
||||
this_code = run_mypy(args, [], files)
|
||||
print("Running mypy " + " ".join(get_mypy_flags(args, "/tmp/...", testing_stdlib=True)))
|
||||
this_code = run_mypy(args, [], files, testing_stdlib=True)
|
||||
code = max(code, this_code)
|
||||
|
||||
return TestResults(code, len(files))
|
||||
@@ -342,7 +352,7 @@ def test_stdlib(code: int, args: TestConfig) -> TestResults:
|
||||
|
||||
def test_third_party_stubs(code: int, args: TestConfig) -> TestResults:
|
||||
print("Testing third-party packages...")
|
||||
print("Running mypy " + " ".join(get_mypy_flags(args, "/tmp/...")))
|
||||
print("Running mypy " + " ".join(get_mypy_flags(args, "/tmp/...", testing_stdlib=False)))
|
||||
files_checked = 0
|
||||
gitignore_spec = get_gitignore_spec()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user