Skip to content
Open
Show file tree
Hide file tree
Changes from 9 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
14 changes: 8 additions & 6 deletions mypy/test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,9 @@ def expand_errors(input: list[str], output: list[str], fnam: str) -> None:

for i in range(len(input)):
# The first in the split things isn't a comment
for possible_err_comment in input[i].split(" # ")[1:]:
for possible_err_comment in re.split(r"(?!\\)#\s*(?=[ENW]\s*:)", input[i])[1:]:
m = re.search(
r"^([ENW]):((?P<col>\d+):)? (?P<message>.*)$", possible_err_comment.strip()
r"^([ENW])\s*:((?P<col>\d+):)?(?P<message>.*)$", possible_err_comment.strip()
)
if m:
if m.group(1) == "E":
Expand All @@ -545,12 +545,14 @@ def expand_errors(input: list[str], output: list[str], fnam: str) -> None:
elif m.group(1) == "W":
severity = "warning"
col = m.group("col")
message = m.group("message")
message = message.replace("\\#", "#") # adds back escaped # character
message = m.group(
"message"
) # Message may, and probably does, include leading spaces
message = message.replace(r"\#", "#") # adds back escaped # character
if col is None:
output.append(f"{fnam}:{i + 1}: {severity}: {message}")
output.append(f"{fnam}:{i + 1}: {severity}:{message}")
else:
output.append(f"{fnam}:{i + 1}:{col}: {severity}: {message}")
output.append(f"{fnam}:{i + 1}:{col}: {severity}:{message}")


def fix_win_path(line: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion mypy/test/update_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _iter_fixes(
fix_lines = []
for lineno, source_line in enumerate(source_lines, start=1):
reports = reports_by_line.get((file_path, lineno))
comment_match = re.search(r"(?P<indent>\s+)(?P<comment># [EWN]: .+)$", source_line)
comment_match = re.search(r"(?P<indent>\s+)(?P<comment>#\s*[EWN]\s*:.+)$", source_line)
if comment_match:
source_line = source_line[: comment_match.start("indent")] # strip old comment
if reports:
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ with text "abc..."
- note a space after `E:` and `flags:`
- `# E:12` adds column number to the expected error
- use `\` to escape the `#` character and indicate that the rest of the line is part of
the error message
the error message (note that there is no support for using `\\` to escape a backslash itself)
- repeating `# E: ` several times in one line indicates multiple expected errors in one line
- `W: ...` and `N: ...` works exactly like `E: ...`, but report a warning and a note respectively
- lines that don't contain the above should cause no type check errors
Expand Down
Loading