Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mypy test #7478

Merged
merged 5 commits into from
Mar 13, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mypy==0.931
mypy==0.940
pytype==2022.2.23; platform_system != "Windows" and python_version < "3.10"
# must match .pre-commit-config.yaml
black==22.1.0
Expand Down
24 changes: 14 additions & 10 deletions tests/mypy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]:
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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

Expand Down