Skip to content

Commit

Permalink
Tighten regex for output assertion parsing
Browse files Browse the repository at this point in the history
The `severity` group was permissive enough to also capture parts of
the message text if that contained any colons. Update it to only capture
(ASCII) words, and update preceding groups to match at least 1
character.

Fixes typeddjango#155
  • Loading branch information
mjpieters committed Dec 20, 2024
1 parent b9437c8 commit 2dfef3b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions pytest_mypy_plugins/tests/test-regex-assertions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,18 @@
main: |
a = 'hello'
reveal_type(a) # NR: .*banana.*
- case: regex_against_callable_comment
main: |
def foo(bar: str, ham: int = 42) -> set[str | int]:
return {bar, ham}
reveal_type(foo) # NR: Revealed type is "def \(bar: builtins\.str, ham: builtins\.int =\) -> .*"
- case: regex_against_callable_out
regex: yes
main: |
def foo(bar: str, ham: int = 42) -> set[str | int]:
return {bar, ham}
reveal_type(foo)
out: |
main:3: note: Revealed type is "def \(bar: builtins\.str, ham: builtins\.int =\) -> .*"
2 changes: 1 addition & 1 deletion pytest_mypy_plugins/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def extract_output_matchers_from_out(out: str, params: Mapping[str, Any], regex:
lines = render_template(out, params).split("\n")
for line in lines:
match = re.search(
r"^(?P<fname>.*):(?P<lnum>\d*): (?P<severity>.*):((?P<col>\d+):)? (?P<message>.*)$", line.strip()
r"^(?P<fname>.+):(?P<lnum>\d+): (?P<severity>[A-Za-z]+):((?P<col>\d+):)? (?P<message>.*)$", line.strip()
)
if match:
if match.group("severity") == "E":
Expand Down

0 comments on commit 2dfef3b

Please sign in to comment.