Skip to content

Commit 446ae52

Browse files
authored
Merge branch 'master' into mj/fix-regex-assertion-parsing
2 parents 2dfef3b + 2a45fec commit 446ae52

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
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

0 commit comments

Comments
 (0)