[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-01-29 20:42:23 +00:00
parent b035a7b4f1
commit edbe8f1a06
18 changed files with 66 additions and 97 deletions

View File

@ -278,9 +278,9 @@ class TracebackEntry:
Mostly for internal use. Mostly for internal use.
""" """
tbh: Union[ tbh: Union[bool, Callable[[Optional[ExceptionInfo[BaseException]]], bool]] = (
bool, Callable[[Optional[ExceptionInfo[BaseException]]], bool] False
] = False )
for maybe_ns_dct in (self.frame.f_locals, self.frame.f_globals): for maybe_ns_dct in (self.frame.f_locals, self.frame.f_globals):
# in normal cases, f_locals and f_globals are dictionaries # in normal cases, f_locals and f_globals are dictionaries
# however via `exec(...)` / `eval(...)` they can be other types # however via `exec(...)` / `eval(...)` they can be other types
@ -377,12 +377,10 @@ class Traceback(List[TracebackEntry]):
return self return self
@overload @overload
def __getitem__(self, key: "SupportsIndex") -> TracebackEntry: def __getitem__(self, key: "SupportsIndex") -> TracebackEntry: ...
...
@overload @overload
def __getitem__(self, key: slice) -> "Traceback": def __getitem__(self, key: slice) -> "Traceback": ...
...
def __getitem__( def __getitem__(
self, key: Union["SupportsIndex", slice] self, key: Union["SupportsIndex", slice]
@ -1045,15 +1043,15 @@ class FormattedExcinfo:
# full support for exception groups added to ExceptionInfo. # full support for exception groups added to ExceptionInfo.
# See https://github.com/pytest-dev/pytest/issues/9159 # See https://github.com/pytest-dev/pytest/issues/9159
if isinstance(e, BaseExceptionGroup): if isinstance(e, BaseExceptionGroup):
reprtraceback: Union[ reprtraceback: Union[ReprTracebackNative, ReprTraceback] = (
ReprTracebackNative, ReprTraceback ReprTracebackNative(
] = ReprTracebackNative(
traceback.format_exception( traceback.format_exception(
type(excinfo_.value), type(excinfo_.value),
excinfo_.value, excinfo_.value,
excinfo_.traceback[0]._rawentry, excinfo_.traceback[0]._rawentry,
) )
) )
)
else: else:
reprtraceback = self.repr_traceback(excinfo_) reprtraceback = self.repr_traceback(excinfo_)
reprcrash = excinfo_._getreprcrash() reprcrash = excinfo_._getreprcrash()

View File

@ -47,12 +47,10 @@ class Source:
__hash__ = None # type: ignore __hash__ = None # type: ignore
@overload @overload
def __getitem__(self, key: int) -> str: def __getitem__(self, key: int) -> str: ...
...
@overload @overload
def __getitem__(self, key: slice) -> "Source": def __getitem__(self, key: slice) -> "Source": ...
...
def __getitem__(self, key: Union[int, slice]) -> Union[str, "Source"]: def __getitem__(self, key: Union[int, slice]) -> Union[str, "Source"]:
if isinstance(key, int): if isinstance(key, int):

View File

@ -204,12 +204,10 @@ class Stat:
if TYPE_CHECKING: if TYPE_CHECKING:
@property @property
def size(self) -> int: def size(self) -> int: ...
...
@property @property
def mtime(self) -> float: def mtime(self) -> float: ...
...
def __getattr__(self, name: str) -> Any: def __getattr__(self, name: str) -> Any:
return getattr(self._osstatresult, "st_" + name) return getattr(self._osstatresult, "st_" + name)
@ -962,12 +960,10 @@ class LocalPath:
return p return p
@overload @overload
def stat(self, raising: Literal[True] = ...) -> Stat: def stat(self, raising: Literal[True] = ...) -> Stat: ...
...
@overload @overload
def stat(self, raising: Literal[False]) -> Stat | None: def stat(self, raising: Literal[False]) -> Stat | None: ...
...
def stat(self, raising: bool = True) -> Stat | None: def stat(self, raising: bool = True) -> Stat | None:
"""Return an os.stat() tuple.""" """Return an os.stat() tuple."""

View File

@ -669,9 +669,9 @@ class AssertionRewriter(ast.NodeVisitor):
self.enable_assertion_pass_hook = False self.enable_assertion_pass_hook = False
self.source = source self.source = source
self.scope: tuple[ast.AST, ...] = () self.scope: tuple[ast.AST, ...] = ()
self.variables_overwrite: defaultdict[ self.variables_overwrite: defaultdict[tuple[ast.AST, ...], Dict[str, str]] = (
tuple[ast.AST, ...], Dict[str, str] defaultdict(dict)
] = defaultdict(dict) )
def run(self, mod: ast.Module) -> None: def run(self, mod: ast.Module) -> None:
"""Find all assert statements in *mod* and rewrite them.""" """Find all assert statements in *mod* and rewrite them."""

View File

@ -1231,8 +1231,7 @@ def fixture(
Union[Sequence[Optional[object]], Callable[[Any], Optional[object]]] Union[Sequence[Optional[object]], Callable[[Any], Optional[object]]]
] = ..., ] = ...,
name: Optional[str] = ..., name: Optional[str] = ...,
) -> FixtureFunction: ) -> FixtureFunction: ...
...
@overload @overload
@ -1246,8 +1245,7 @@ def fixture( # noqa: F811
Union[Sequence[Optional[object]], Callable[[Any], Optional[object]]] Union[Sequence[Optional[object]], Callable[[Any], Optional[object]]]
] = ..., ] = ...,
name: Optional[str] = None, name: Optional[str] = None,
) -> FixtureFunctionMarker: ) -> FixtureFunctionMarker: ...
...
def fixture( # noqa: F811 def fixture( # noqa: F811

View File

@ -721,14 +721,12 @@ class Session(nodes.Collector):
@overload @overload
def perform_collect( def perform_collect(
self, args: Optional[Sequence[str]] = ..., genitems: "Literal[True]" = ... self, args: Optional[Sequence[str]] = ..., genitems: "Literal[True]" = ...
) -> Sequence[nodes.Item]: ) -> Sequence[nodes.Item]: ...
...
@overload @overload
def perform_collect( # noqa: F811 def perform_collect( # noqa: F811
self, args: Optional[Sequence[str]] = ..., genitems: bool = ... self, args: Optional[Sequence[str]] = ..., genitems: bool = ...
) -> Sequence[Union[nodes.Item, nodes.Collector]]: ) -> Sequence[Union[nodes.Item, nodes.Collector]]: ...
...
def perform_collect( # noqa: F811 def perform_collect( # noqa: F811
self, args: Optional[Sequence[str]] = None, genitems: bool = True self, args: Optional[Sequence[str]] = None, genitems: bool = True

View File

@ -434,12 +434,10 @@ if TYPE_CHECKING:
class _SkipMarkDecorator(MarkDecorator): class _SkipMarkDecorator(MarkDecorator):
@overload # type: ignore[override,misc,no-overload-impl] @overload # type: ignore[override,misc,no-overload-impl]
def __call__(self, arg: Markable) -> Markable: def __call__(self, arg: Markable) -> Markable: ...
...
@overload @overload
def __call__(self, reason: str = ...) -> "MarkDecorator": def __call__(self, reason: str = ...) -> "MarkDecorator": ...
...
class _SkipifMarkDecorator(MarkDecorator): class _SkipifMarkDecorator(MarkDecorator):
def __call__( # type: ignore[override] def __call__( # type: ignore[override]
@ -447,13 +445,11 @@ if TYPE_CHECKING:
condition: Union[str, bool] = ..., condition: Union[str, bool] = ...,
*conditions: Union[str, bool], *conditions: Union[str, bool],
reason: str = ..., reason: str = ...,
) -> MarkDecorator: ) -> MarkDecorator: ...
...
class _XfailMarkDecorator(MarkDecorator): class _XfailMarkDecorator(MarkDecorator):
@overload # type: ignore[override,misc,no-overload-impl] @overload # type: ignore[override,misc,no-overload-impl]
def __call__(self, arg: Markable) -> Markable: def __call__(self, arg: Markable) -> Markable: ...
...
@overload @overload
def __call__( def __call__(
@ -466,8 +462,7 @@ if TYPE_CHECKING:
None, Type[BaseException], Tuple[Type[BaseException], ...] None, Type[BaseException], Tuple[Type[BaseException], ...]
] = ..., ] = ...,
strict: bool = ..., strict: bool = ...,
) -> MarkDecorator: ) -> MarkDecorator: ...
...
class _ParametrizeMarkDecorator(MarkDecorator): class _ParametrizeMarkDecorator(MarkDecorator):
def __call__( # type: ignore[override] def __call__( # type: ignore[override]
@ -483,8 +478,7 @@ if TYPE_CHECKING:
] ]
] = ..., ] = ...,
scope: Optional[_ScopeName] = ..., scope: Optional[_ScopeName] = ...,
) -> MarkDecorator: ) -> MarkDecorator: ...
...
class _UsefixturesMarkDecorator(MarkDecorator): class _UsefixturesMarkDecorator(MarkDecorator):
def __call__(self, *fixtures: str) -> MarkDecorator: # type: ignore[override] def __call__(self, *fixtures: str) -> MarkDecorator: # type: ignore[override]

View File

@ -169,8 +169,7 @@ class MonkeyPatch:
name: object, name: object,
value: Notset = ..., value: Notset = ...,
raising: bool = ..., raising: bool = ...,
) -> None: ) -> None: ...
...
@overload @overload
def setattr( def setattr(
@ -179,8 +178,7 @@ class MonkeyPatch:
name: str, name: str,
value: object, value: object,
raising: bool = ..., raising: bool = ...,
) -> None: ) -> None: ...
...
def setattr( def setattr(
self, self,

View File

@ -104,6 +104,7 @@ class Node(abc.ABC, metaclass=NodeMeta):
``Collector``\'s are the internal nodes of the tree, and ``Item``\'s are the ``Collector``\'s are the internal nodes of the tree, and ``Item``\'s are the
leaf nodes. leaf nodes.
""" """
# Use __slots__ to make attribute access faster. # Use __slots__ to make attribute access faster.
# Note that __dict__ is still available. # Note that __dict__ is still available.
__slots__ = ( __slots__ = (
@ -325,12 +326,10 @@ class Node(abc.ABC, metaclass=NodeMeta):
yield node, mark yield node, mark
@overload @overload
def get_closest_marker(self, name: str) -> Optional[Mark]: def get_closest_marker(self, name: str) -> Optional[Mark]: ...
...
@overload @overload
def get_closest_marker(self, name: str, default: Mark) -> Mark: def get_closest_marker(self, name: str, default: Mark) -> Mark: ...
...
def get_closest_marker( def get_closest_marker(
self, name: str, default: Optional[Mark] = None self, name: str, default: Optional[Mark] = None

View File

@ -244,8 +244,7 @@ class RecordedHookCall:
if TYPE_CHECKING: if TYPE_CHECKING:
# The class has undetermined attributes, this tells mypy about it. # The class has undetermined attributes, this tells mypy about it.
def __getattr__(self, key: str): def __getattr__(self, key: str): ...
...
@final @final
@ -326,15 +325,13 @@ class HookRecorder:
def getreports( def getreports(
self, self,
names: "Literal['pytest_collectreport']", names: "Literal['pytest_collectreport']",
) -> Sequence[CollectReport]: ) -> Sequence[CollectReport]: ...
...
@overload @overload
def getreports( def getreports(
self, self,
names: "Literal['pytest_runtest_logreport']", names: "Literal['pytest_runtest_logreport']",
) -> Sequence[TestReport]: ) -> Sequence[TestReport]: ...
...
@overload @overload
def getreports( def getreports(
@ -343,8 +340,7 @@ class HookRecorder:
"pytest_collectreport", "pytest_collectreport",
"pytest_runtest_logreport", "pytest_runtest_logreport",
), ),
) -> Sequence[Union[CollectReport, TestReport]]: ) -> Sequence[Union[CollectReport, TestReport]]: ...
...
def getreports( def getreports(
self, self,
@ -391,15 +387,13 @@ class HookRecorder:
def getfailures( def getfailures(
self, self,
names: "Literal['pytest_collectreport']", names: "Literal['pytest_collectreport']",
) -> Sequence[CollectReport]: ) -> Sequence[CollectReport]: ...
...
@overload @overload
def getfailures( def getfailures(
self, self,
names: "Literal['pytest_runtest_logreport']", names: "Literal['pytest_runtest_logreport']",
) -> Sequence[TestReport]: ) -> Sequence[TestReport]: ...
...
@overload @overload
def getfailures( def getfailures(
@ -408,8 +402,7 @@ class HookRecorder:
"pytest_collectreport", "pytest_collectreport",
"pytest_runtest_logreport", "pytest_runtest_logreport",
), ),
) -> Sequence[Union[CollectReport, TestReport]]: ) -> Sequence[Union[CollectReport, TestReport]]: ...
...
def getfailures( def getfailures(
self, self,

View File

@ -1793,9 +1793,11 @@ class Function(PyobjMixin, nodes.Item):
if self.config.getoption("tbstyle", "auto") == "auto": if self.config.getoption("tbstyle", "auto") == "auto":
if len(ntraceback) > 2: if len(ntraceback) > 2:
ntraceback = Traceback( ntraceback = Traceback(
(
entry entry
if i == 0 or i == len(ntraceback) - 1 if i == 0 or i == len(ntraceback) - 1
else entry.with_repr_style("short") else entry.with_repr_style("short")
)
for i, entry in enumerate(ntraceback) for i, entry in enumerate(ntraceback)
) )

View File

@ -779,8 +779,7 @@ def raises(
expected_exception: Union[Type[E], Tuple[Type[E], ...]], expected_exception: Union[Type[E], Tuple[Type[E], ...]],
*, *,
match: Optional[Union[str, Pattern[str]]] = ..., match: Optional[Union[str, Pattern[str]]] = ...,
) -> "RaisesContext[E]": ) -> "RaisesContext[E]": ...
...
@overload @overload
@ -789,8 +788,7 @@ def raises( # noqa: F811
func: Callable[..., Any], func: Callable[..., Any],
*args: Any, *args: Any,
**kwargs: Any, **kwargs: Any,
) -> _pytest._code.ExceptionInfo[E]: ) -> _pytest._code.ExceptionInfo[E]: ...
...
def raises( # noqa: F811 def raises( # noqa: F811

View File

@ -42,15 +42,13 @@ def recwarn() -> Generator["WarningsRecorder", None, None]:
@overload @overload
def deprecated_call( def deprecated_call(
*, match: Optional[Union[str, Pattern[str]]] = ... *, match: Optional[Union[str, Pattern[str]]] = ...
) -> "WarningsRecorder": ) -> "WarningsRecorder": ...
...
@overload @overload
def deprecated_call( # noqa: F811 def deprecated_call( # noqa: F811
func: Callable[..., T], *args: Any, **kwargs: Any func: Callable[..., T], *args: Any, **kwargs: Any
) -> T: ) -> T: ...
...
def deprecated_call( # noqa: F811 def deprecated_call( # noqa: F811
@ -92,8 +90,7 @@ def warns(
expected_warning: Union[Type[Warning], Tuple[Type[Warning], ...]] = ..., expected_warning: Union[Type[Warning], Tuple[Type[Warning], ...]] = ...,
*, *,
match: Optional[Union[str, Pattern[str]]] = ..., match: Optional[Union[str, Pattern[str]]] = ...,
) -> "WarningsChecker": ) -> "WarningsChecker": ...
...
@overload @overload
@ -102,8 +99,7 @@ def warns( # noqa: F811
func: Callable[..., T], func: Callable[..., T],
*args: Any, *args: Any,
**kwargs: Any, **kwargs: Any,
) -> T: ) -> T: ...
...
def warns( # noqa: F811 def warns( # noqa: F811

View File

@ -71,8 +71,7 @@ class BaseReport:
if TYPE_CHECKING: if TYPE_CHECKING:
# Can have arbitrary fields given to __init__(). # Can have arbitrary fields given to __init__().
def __getattr__(self, key: str) -> Any: def __getattr__(self, key: str) -> Any: ...
...
def toterminal(self, out: TerminalWriter) -> None: def toterminal(self, out: TerminalWriter) -> None:
if hasattr(self, "node"): if hasattr(self, "node"):
@ -609,9 +608,9 @@ def _report_kwargs_from_json(reportdict: Dict[str, Any]) -> Dict[str, Any]:
description, description,
) )
) )
exception_info: Union[ exception_info: Union[ExceptionChainRepr, ReprExceptionInfo] = (
ExceptionChainRepr, ReprExceptionInfo ExceptionChainRepr(chain)
] = ExceptionChainRepr(chain) )
else: else:
exception_info = ReprExceptionInfo( exception_info = ReprExceptionInfo(
reprtraceback=reprtraceback, reprtraceback=reprtraceback,

View File

@ -1,4 +1,5 @@
"""Generate an executable with pytest runner embedded using PyInstaller.""" """Generate an executable with pytest runner embedded using PyInstaller."""
if __name__ == "__main__": if __name__ == "__main__":
import pytest import pytest
import subprocess import subprocess

View File

@ -2,6 +2,7 @@
Called by tox.ini: uses the generated executable to run the tests in ./tests/ Called by tox.ini: uses the generated executable to run the tests in ./tests/
directory. directory.
""" """
if __name__ == "__main__": if __name__ == "__main__":
import os import os
import sys import sys

View File

@ -2109,9 +2109,9 @@ class TestPytestPluginsVariable:
args = ("--pyargs", "pkg") if use_pyargs else () args = ("--pyargs", "pkg") if use_pyargs else ()
res = pytester.runpytest(*args) res = pytester.runpytest(*args)
assert res.ret == (0 if use_pyargs else 2) assert res.ret == (0 if use_pyargs else 2)
msg = ( msg = msg = (
msg "Defining 'pytest_plugins' in a non-top-level conftest is no longer supported"
) = "Defining 'pytest_plugins' in a non-top-level conftest is no longer supported" )
if use_pyargs: if use_pyargs:
assert msg not in res.stdout.str() assert msg not in res.stdout.str()
else: else:

View File

@ -296,9 +296,9 @@ class TestReportSerialization:
reprec = pytester.inline_run() reprec = pytester.inline_run()
if report_class is TestReport: if report_class is TestReport:
reports: Union[ reports: Union[Sequence[TestReport], Sequence[CollectReport]] = (
Sequence[TestReport], Sequence[CollectReport] reprec.getreports("pytest_runtest_logreport")
] = reprec.getreports("pytest_runtest_logreport") )
# we have 3 reports: setup/call/teardown # we have 3 reports: setup/call/teardown
assert len(reports) == 3 assert len(reports) == 3
# get the call report # get the call report