Fix mypy test (#7478)

* Fix `mypy_test.py` so that it actually tests the third-party stubs
* Upgrade to mypy 0.940
* Skip running mypy on `SQLAlchemy` stubs for now, to workaround a mypy crash.

Because we didn't set mypy's clean_exit parameter, it was exiting immediately after checking the stdlib, meaning `mypy_test.py` wasn't checking the third-party stubs at all.

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Jelle Zijlstra
2022-03-13 06:01:14 -07:00
committed by GitHub
parent 3e3cc2a6d6
commit fa332220b7
2 changed files with 15 additions and 11 deletions

View File

@@ -171,7 +171,7 @@ def add_configuration(configurations: list[MypyDistConf], distribution: str) ->
def run_mypy(args, configurations, major, minor, files, *, custom_typeshed=False):
try:
from mypy.main import main as mypy_main
from mypy.api import run as mypy_run
except ImportError:
print("Cannot import mypy. Did you install it?")
sys.exit(1)
@@ -185,15 +185,16 @@ def run_mypy(args, configurations, major, minor, files, *, custom_typeshed=False
temp.flush()
flags = get_mypy_flags(args, major, minor, temp.name, custom_typeshed=custom_typeshed)
sys.argv = ["mypy"] + flags + files
mypy_args = [*flags, *files]
if args.verbose:
print("running", " ".join(sys.argv))
if not args.dry_run:
try:
mypy_main("", sys.stdout, sys.stderr)
except SystemExit as err:
return err.code
return 0
print("running mypy", " ".join(mypy_args))
if args.dry_run:
exit_code = 0
else:
stdout, stderr, exit_code = mypy_run(mypy_args)
print(stdout, end="")
print(stderr, file=sys.stderr, end="")
return exit_code
def get_mypy_flags(args, major: int, minor: int, temp_name: str, *, custom_typeshed: bool = False) -> list[str]:
@@ -231,7 +232,7 @@ def read_dependencies(distribution: str) -> list[str]:
for dependency in requires:
assert isinstance(dependency, str)
assert dependency.startswith("types-")
dependencies.append(dependency[6:])
dependencies.append(dependency[6:].split("<")[0])
return dependencies
@@ -323,6 +324,9 @@ def main():
# Test files of all third party distributions.
print("Running mypy " + " ".join(get_mypy_flags(args, major, minor, "/tmp/...")))
for distribution in sorted(os.listdir("stubs")):
if distribution == "SQLAlchemy":
continue # Crashes
if not is_supported(distribution, major):
continue