diff --git a/stubs/protobuf/METADATA.toml b/stubs/protobuf/METADATA.toml index 06628e4dc..ad087c2d7 100644 --- a/stubs/protobuf/METADATA.toml +++ b/stubs/protobuf/METADATA.toml @@ -1,2 +1,2 @@ -version = "3.20.*" +version = "4.21.*" extra_description = "Generated with aid from mypy-protobuf v3.4.0" diff --git a/stubs/protobuf/google/__init__.pyi b/stubs/protobuf/google/__init__.pyi deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/mypy_test.py b/tests/mypy_test.py index b0da93eec..a0069ae69 100644 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -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()