From 1ebaf62270ff57f012bdc043217c4a3323d99ed5 Mon Sep 17 00:00:00 2001 From: stubsabot <> Date: Thu, 27 Oct 2022 00:13:20 +0000 Subject: [PATCH 1/4] [stubsabot] Bump protobuf to 4.21.* Release: https://pypi.org/pypi/protobuf/4.21.9 Homepage: https://developers.google.com/protocol-buffers/ If stubtest fails for this PR: - Leave this PR open (as a reminder, and to prevent stubsabot from opening another PR) - Fix stubtest failures in another PR, then close this PR Note that you will need to close and re-open the PR in order to trigger CI --- stubs/protobuf/METADATA.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/protobuf/METADATA.toml b/stubs/protobuf/METADATA.toml index 06628e4dcca2..ad087c2d74b6 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" From a7060ab1235afa53c1b04fa0ecff8a3e23d88e59 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Thu, 10 Nov 2022 18:04:44 +0000 Subject: [PATCH 2/4] Delete __init__.pyi --- stubs/protobuf/google/__init__.pyi | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 stubs/protobuf/google/__init__.pyi diff --git a/stubs/protobuf/google/__init__.pyi b/stubs/protobuf/google/__init__.pyi deleted file mode 100644 index e69de29bb2d1..000000000000 From f47186073a49b07e5a407fc7afaa4c0d055fd677 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Wed, 23 Nov 2022 20:09:56 +0000 Subject: [PATCH 3/4] Fix --- tests/mypy_test.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/mypy_test.py b/tests/mypy_test.py index b0da93eececc..b1daee6d65d4 100644 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -32,6 +32,12 @@ 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")] @@ -199,12 +205,6 @@ def add_configuration(configurations: list[MypyDistConf], distribution: str) -> 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) - with tempfile.NamedTemporaryFile("w+") as temp: temp.write("[mypy]\n") for dist_conf in configurations: @@ -315,7 +315,14 @@ def test_third_party_distribution(distribution: str, args: TestConfig) -> TestRe print_error("no files found") sys.exit(1) + 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) + if prev_mypypath is None: + del os.environ["MYPYPATH"] + else: + os.environ["MYPYPATH"] = prev_mypypath + return TestResults(code, len(files)) From bb8deee29ae2a0799f6fcf62817fa9da246d275f Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Wed, 23 Nov 2022 20:17:28 +0000 Subject: [PATCH 4/4] Use `--explicit-package-bases` on non-stdlib stubs --- tests/mypy_test.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/mypy_test.py b/tests/mypy_test.py index b1daee6d65d4..a0069ae69acd 100644 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -204,7 +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: +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( @@ -317,7 +320,7 @@ def test_third_party_distribution(distribution: str, args: TestConfig) -> TestRe 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) + code = run_mypy(args, configurations, files, testing_stdlib=False) if prev_mypypath is None: del os.environ["MYPYPATH"] else: @@ -340,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)) @@ -349,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()