Skip to content

Commit 6557c26

Browse files
authored
Merge branch 'master' into fix-internalerror-2
2 parents 587371e + c26355c commit 6557c26

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

pytest_mypy_plugins/item.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@
66
import sys
77
import tempfile
88
from pathlib import Path
9-
from typing import TYPE_CHECKING, Any, Dict, List, Optional, TextIO, Tuple, Union
9+
from typing import (
10+
TYPE_CHECKING,
11+
Any,
12+
Dict,
13+
List,
14+
Literal,
15+
Optional,
16+
TextIO,
17+
Tuple,
18+
Union,
19+
)
1020

1121
import py
1222
import pytest
@@ -18,9 +28,6 @@
1828
from mypy.fscache import FileSystemCache
1929
from mypy.main import process_options
2030

21-
if TYPE_CHECKING:
22-
from _pytest._code.code import _TracebackStyle
23-
2431
from pytest_mypy_plugins import configs, utils
2532
from pytest_mypy_plugins.collect import File, YamlTestFile
2633
from pytest_mypy_plugins.utils import (
@@ -30,6 +37,13 @@
3037
fname_to_module,
3138
)
3239

40+
if TYPE_CHECKING:
41+
# pytest 8.3.0 renamed _TracebackStyle to TracebackStyle, but there is no syntax
42+
# to assert what version you have using static conditions, so it has to be
43+
# manually re-defined here. Once minimum supported pytest version is >= 8.3.0,
44+
# the following can be replaced with `from _pytest._code.code import TracebackStyle`
45+
TracebackStyle = Literal["long", "short", "line", "no", "native", "value", "auto"]
46+
3347

3448
class TraceLastReprEntry(ReprEntry):
3549
def toterminal(self, tw: TerminalWriter) -> None:
@@ -443,7 +457,7 @@ def prepare_config_file(self, execution_path: Path) -> Optional[str]:
443457
return None
444458

445459
def repr_failure(
446-
self, excinfo: ExceptionInfo[BaseException], style: Optional["_TracebackStyle"] = None
460+
self, excinfo: ExceptionInfo[BaseException], style: Optional["TracebackStyle"] = None
447461
) -> Union[str, TerminalRepr]:
448462
if excinfo.errisinstance(SystemExit):
449463
# We assume that before doing exit() (which raises SystemExit) we've printed

pytest_mypy_plugins/tests/test-regex-assertions.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,22 @@
5454
main: |
5555
a = 'hello'
5656
reveal_type(a) # NR: .*banana.*
57+
58+
- case: regex_against_callable_comment
59+
main: |
60+
from typing import Set, Union
61+
62+
def foo(bar: str, ham: int = 42) -> Set[Union[str, int]]:
63+
return {bar, ham}
64+
reveal_type(foo) # NR: Revealed type is "def \(bar: builtins\.str, ham: builtins\.int =\) -> .*"
65+
66+
- case: regex_against_callable_out
67+
regex: yes
68+
main: |
69+
from typing import Set, Union
70+
71+
def foo(bar: str, ham: int = 42) -> Set[Union[str, int]]:
72+
return {bar, ham}
73+
reveal_type(foo)
74+
out: |
75+
main:5: note: Revealed type is "def \(bar: builtins\.str, ham: builtins\.int =\) -> .*"

pytest_mypy_plugins/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def extract_output_matchers_from_out(out: str, params: Mapping[str, Any], regex:
326326
lines = render_template(out, params).split("\n")
327327
for line in lines:
328328
match = re.search(
329-
r"^(?P<fname>.*):(?P<lnum>\d*): (?P<severity>.*):((?P<col>\d+):)? (?P<message>.*)$", line.strip()
329+
r"^(?P<fname>.+):(?P<lnum>\d+): (?P<severity>[A-Za-z]+):((?P<col>\d+):)? (?P<message>.*)$", line.strip()
330330
)
331331
if match:
332332
if match.group("severity") == "E":

0 commit comments

Comments
 (0)