Skip to content

Commit 49a31c5

Browse files
committed
Improve iterable-sequence error message
1 parent e644c40 commit 49a31c5

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

mypy_pytest_plugin/iterable_sequence_checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _display_error_message(
4343
self, expected_type: Type, argument_type: Type, context: Context
4444
) -> None:
4545
self.checker.fail(
46-
f"Expected {format_type(expected_type, self.checker.options)}, got {format_type(argument_type, self.checker.options)}.",
46+
f"Argument has type {format_type(argument_type, self.checker.options)}; expected {format_type(expected_type, self.checker.options)}.",
4747
context,
4848
code=ITERABLE_SEQUENCE,
4949
)

mypy_pytest_plugin/plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def __init__(self, options: Options) -> None:
3131
options.per_module_options.setdefault(module_pattern, {})["ignore_missing_imports"] = (
3232
True
3333
)
34+
options.preserve_asts = True
3435
super().__init__(options)
3536

3637
def get_additional_deps(self, file: MypyFile) -> list[tuple[int, str, int]]:

tests/snapshots/mypy_test/test_check_files/invalid_test/invalid_test.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ test_samples/invalid_test.py:23: error: Argument 2 has incompatible type "tuple[
77
test_samples/invalid_test.py:30: error: Incompatible return value type (got "list[T]", expected "tuple[T, T]") [return-value]
88
test_samples/invalid_test.py:34: error: Argument 1 to "specific_test_case" has incompatible type "str"; expected "int" [arg-type]
99
test_samples/invalid_test.py:34: error: Argument 1 to "specific_test_case" has incompatible type "float"; expected "int" [arg-type]
10-
test_samples/invalid_test.py:47: error: Expected "Iterable[Any]", got "list[Any]". [iterable-sequence]
10+
test_samples/invalid_test.py:47: error: Argument has type "list[Any]"; expected "Iterable[Any]". [iterable-sequence]
1111
test_samples/invalid_test.py:47: note: This still type checks, but could be made more robust by using `iter()`
12-
test_samples/invalid_test.py:48: error: Expected "Iterable[int]", got "list[int]". [iterable-sequence]
12+
test_samples/invalid_test.py:48: error: Argument has type "list[int]"; expected "Iterable[int]". [iterable-sequence]
1313
test_samples/invalid_test.py:48: note: This still type checks, but could be made more robust by using `iter()`
1414
test_samples/invalid_test.py:61: error: Function is missing a type annotation [no-untyped-def]
1515
Found 12 errors in 1 file (checked 1 source file)

0 commit comments

Comments
 (0)