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

Add test cases for pow that are meant to fail a type check #7760

Merged
merged 15 commits into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 8 additions & 0 deletions test_cases/stdlib/builtins/test_pow.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,11 @@
assert_type(pow(4.7, 9.2, None), Any)
# See #7046 -- float for a positive 1st arg, complex otherwise
assert_type((-95) ** 8.42, Any)

# All of these should fail a type-checker
# mypy will emit an error if any of them do not fail,
# since we use --warn-unused-ignores when checking this subdirectory
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
pow(1.9, 4, 6) # type: ignore[misc]
pow(complex(6), 6.2, 7) # type: ignore[misc]
pow(Fraction(), 5, 8) # type: ignore[call-overload]
Decimal("8.7") ** 3.14 # type: ignore[operator]
7 changes: 6 additions & 1 deletion tests/mypy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import argparse
import os
import re
import shutil
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -375,7 +376,11 @@ def test_the_test_cases(code: int, major: int, minor: int, args: argparse.Namesp
if args.dry_run:
this_code = 0
else:
this_code = subprocess.run([sys.executable, "-m", "mypy", "test_cases", *flags]).returncode
# --warn-unused-ignores doesn't work for files inside typeshed.
# SO, to work around this, we copy the test_cases directory into a TemporaryDirectory.
with tempfile.TemporaryDirectory() as td:
shutil.copytree(Path("test_cases"), Path(td) / "test_cases")
this_code = subprocess.run([sys.executable, "-m", "mypy", td, *flags]).returncode
code = max(code, this_code)
return TestResults(code, num_test_case_files)

Expand Down