[ruff] Fix all consider [*cats, garfield] instead of cats + [garfield]

This commit is contained in:
Pierre Sassoulas 2024-02-02 15:12:50 +01:00
parent 8967c527ff
commit 233ab89f13
14 changed files with 25 additions and 28 deletions

View File

@ -158,7 +158,6 @@ ignore = [
"D404", # First word of the docstring should not be "This"
"D415", # First line should end with a period, question mark, or exclamation point
# ruff ignore
"RUF005", # Consider `(x, *y)` instead of concatenation
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
]

View File

@ -107,7 +107,7 @@ def pre_release(
def changelog(version: str, write_out: bool = False) -> None:
addopts = [] if write_out else ["--draft"]
check_call(["towncrier", "--yes", "--version", version] + addopts)
check_call(["towncrier", "--yes", "--version", version, *addopts])
def main() -> None:

View File

@ -925,7 +925,7 @@ class AssertionRewriter(ast.NodeVisitor):
# If any hooks implement assert_pass hook
hook_impl_test = ast.If(
self.helper("_check_if_assertion_pass_impl"),
self.expl_stmts + [hook_call_pass],
[*self.expl_stmts, hook_call_pass],
[],
)
statements_pass = [hook_impl_test]

View File

@ -92,7 +92,8 @@ def _truncate_explanation(
else:
# Add proper ellipsis when we were able to fit a full line exactly
truncated_explanation[-1] = "..."
return truncated_explanation + [
return [
*truncated_explanation,
"",
f"...Full output truncated ({truncated_line_count} line"
f"{'' if truncated_line_count == 1 else 's'} hidden), {USAGE_MSG}",

View File

@ -233,8 +233,8 @@ def assertrepr_compare(
return None
if explanation[0] != "":
explanation = [""] + explanation
return [summary] + explanation
explanation = ["", *explanation]
return [summary, *explanation]
def _compare_eq_any(

View File

@ -238,7 +238,8 @@ essential_plugins = (
"helpconfig", # Provides -p.
)
default_plugins = essential_plugins + (
default_plugins = (
*essential_plugins,
"python",
"terminal",
"debugging",

View File

@ -122,7 +122,7 @@ class Parser:
from _pytest._argcomplete import filescompleter
optparser = MyOptionParser(self, self.extra_info, prog=self.prog)
groups = self._groups + [self._anonymous]
groups = [*self._groups, self._anonymous]
for group in groups:
if group.options:
desc = group.description or group.name

View File

@ -1061,7 +1061,7 @@ class Pytester:
:param cmdlineargs: Any extra command line arguments to use.
"""
p = self.makepyfile(source)
values = list(cmdlineargs) + [p]
values = [*list(cmdlineargs), p]
return self.inline_run(*values)
def inline_genitems(self, *args) -> Tuple[List[Item], HookRecorder]:
@ -1491,10 +1491,10 @@ class Pytester:
"""
__tracebackhide__ = True
p = make_numbered_dir(root=self.path, prefix="runpytest-", mode=0o700)
args = ("--basetemp=%s" % p,) + args
args = ("--basetemp=%s" % p, *args)
plugins = [x for x in self.plugins if isinstance(x, str)]
if plugins:
args = ("-p", plugins[0]) + args
args = ("-p", plugins[0], *args)
args = self._getpytestargs() + args
return self.run(*args, timeout=timeout)

View File

@ -79,7 +79,7 @@ def deprecated_call(
"""
__tracebackhide__ = True
if func is not None:
args = (func,) + args
args = (func, *args)
return warns(
(DeprecationWarning, PendingDeprecationWarning, FutureWarning), *args, **kwargs
)

View File

@ -1739,7 +1739,7 @@ def test_hidden_entries_of_chained_exceptions_are_not_shown(pytester: Pytester)
def add_note(err: BaseException, msg: str) -> None:
"""Adds a note to an exception inplace."""
if sys.version_info < (3, 11):
err.__notes__ = getattr(err, "__notes__", []) + [msg] # type: ignore[attr-defined]
err.__notes__ = [*getattr(err, "__notes__", []), msg] # type: ignore[attr-defined]
else:
err.add_note(msg)

View File

@ -9,5 +9,5 @@ if __name__ == "__main__":
for x in pytest.freeze_includes():
hidden.extend(["--hidden-import", x])
hidden.extend(["--hidden-import", "distutils"])
args = ["pyinstaller", "--noconfirm"] + hidden + ["runtests_script.py"]
args = ["pyinstaller", "--noconfirm", *hidden, "runtests_script.py"]
subprocess.check_call(" ".join(args), shell=True)

View File

@ -4536,5 +4536,5 @@ def test_yield_fixture_with_no_value(pytester: Pytester) -> None:
def test_deduplicate_names() -> None:
items = deduplicate_names("abacd")
assert items == ("a", "b", "c", "d")
items = deduplicate_names(items + ("g", "f", "g", "e", "b"))
items = deduplicate_names((*items, "g", "f", "g", "e", "b"))
assert items == ("a", "b", "c", "d", "g", "f", "e")

View File

@ -42,7 +42,7 @@ class RunAndParse:
self, *args: Union[str, "os.PathLike[str]"], family: Optional[str] = "xunit1"
) -> Tuple[RunResult, "DomNode"]:
if family:
args = ("-o", "junit_family=" + family) + args
args = ("-o", "junit_family=" + family, *args)
xml_path = self.pytester.path.joinpath("junit.xml")
result = self.pytester.runpytest("--junitxml=%s" % xml_path, *args)
if family == "xunit2":

View File

@ -417,8 +417,8 @@ class TestTerminal:
result = pytester.runpytest("-v")
result.stdout.fnmatch_lines(
common_output
+ [
[
*common_output,
"test_verbose_skip_reason.py::test_long_skip SKIPPED (1 cannot *...) *",
"test_verbose_skip_reason.py::test_long_xfail XFAIL (2 cannot *...) *",
]
@ -426,17 +426,13 @@ class TestTerminal:
result = pytester.runpytest("-vv")
result.stdout.fnmatch_lines(
common_output
+ [
(
"test_verbose_skip_reason.py::test_long_skip SKIPPED"
" (1 cannot do foobar"
),
[
*common_output,
"test_verbose_skip_reason.py::test_long_skip SKIPPED"
" (1 cannot do foobar",
"because baz is missing due to I don't know what) *",
(
"test_verbose_skip_reason.py::test_long_xfail XFAIL"
" (2 cannot do foobar"
),
"test_verbose_skip_reason.py::test_long_xfail XFAIL"
" (2 cannot do foobar",
"because baz is missing due to I don't know what) *",
]
)