Skip to content

Commit 5056944

Browse files
test and documentation changes
1 parent 9018224 commit 5056944

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

mypy/test/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ def trimmed_newlines(self) -> int: # compensates for strip_list
445445

446446

447447
def parse_test_data(raw_data: str, name: str) -> list[TestItem]:
448-
"""Parse a list of lines that represent a sequence of test items."""
448+
"""Parse a multi-line text that represents a sequence of test items in a single test case."""
449449

450450
lines = ["", "[case " + name + "]"] + raw_data.split("\n")
451451
ret: list[TestItem] = []

mypy/test/meta/test_update_data.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,27 @@ def test_update_data(self) -> None:
4949
s: str = 'foo' # W: foo \
5050
# N: bar
5151
52+
[case testIndentationOfMultiline]
53+
s: str = 42; i: int = 'foo' # E: Incompatible types in assignment (expression has type "int", variable has type "str")\
54+
# E: Incompatible types in assignment (expression has type "int", variable has type "str")
55+
s2: str = 42; i2: int = 'foo' # E: Incompatible types in assignment (expression has type "int", variable has type "str")\
56+
# E: Incompatible types in assignment (expression has type "int", variable has type "str")
57+
5258
[case testOutCorrect]
5359
s: str = 42
5460
[out]
5561
main:1: error: Incompatible types in assignment (expression has type "int", variable has type "str")
5662
63+
[case testOutWithMuchTraillingWhitespace]
64+
s: str = 42
65+
[out]
66+
main:1: error: Incompatible types in assignment (expression has type "int", variable has type "str")
67+
68+
69+
70+
71+
72+
5773
[case testOutWrong]
5874
s: str = 42
5975
[out]
@@ -105,11 +121,27 @@ def test_update_data(self) -> None:
105121
[case testExtraneousMultilineNonError]
106122
s: str = 'foo'
107123
124+
[case testIndentationOfMultiline]
125+
s: str = 42; i: int = 'foo' # E: Incompatible types in assignment (expression has type "int", variable has type "str") \
126+
# E: Incompatible types in assignment (expression has type "str", variable has type "int")
127+
s2: str = 42; i2: int = 'foo' # E: Incompatible types in assignment (expression has type "int", variable has type "str") \
128+
# E: Incompatible types in assignment (expression has type "str", variable has type "int")
129+
108130
[case testOutCorrect]
109131
s: str = 42
110132
[out]
111133
main:1: error: Incompatible types in assignment (expression has type "int", variable has type "str")
112134
135+
[case testOutWithMuchTraillingWhitespace]
136+
s: str = 42
137+
[out]
138+
main:1: error: Incompatible types in assignment (expression has type "int", variable has type "str")
139+
140+
141+
142+
143+
144+
113145
[case testOutWrong]
114146
s: str = 42
115147
[out]

mypy/test/update_data.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,19 @@ def _iter_fixes(
6363

6464
fix_lines = []
6565
for lineno, source_line in enumerate(source_lines, start=1):
66-
reports = reports_by_line.get((file_path, lineno))
66+
reports_on_this_line = reports_by_line.get((file_path, lineno))
6767
comment_match = re.search(r"(?P<indent>\s+)(?P<comment># [EWN]: .+)$", source_line)
6868
if comment_match:
6969
source_line = source_line[: comment_match.start("indent")] # strip old comment
70-
if reports:
70+
if reports_on_this_line:
7171
indent = comment_match.group("indent") if comment_match else " "
72-
# multiline comments are on the first line and then on subsequent lines empty lines
73-
# with a continuation backslash
74-
for j, (severity, msg) in enumerate(reports):
75-
out_l = source_line if j == 0 else " " * len(source_line)
76-
is_last = j == len(reports) - 1
72+
# Multiple info reports for the same line are represented in these
73+
# comments with the first on the relevant line, then the subsequent
74+
# ones on subsequent empty (indented) lines
75+
# using continuation backslashes
76+
for i, (severity, msg) in enumerate(reports_on_this_line):
77+
out_l = source_line if i == 0 else " " * len(source_line)
78+
is_last = (i == len(reports_on_this_line) - 1)
7779
severity_char = severity[0].upper()
7880
continuation = "" if is_last else " \\"
7981
fix_lines.append(f"{out_l}{indent}# {severity_char}: {msg}{continuation}")

0 commit comments

Comments
 (0)