Skip to content

Commit 5be64c3

Browse files
Merge pull request #11912 from Pierre-Sassoulas/activate-ruff-checks
[pre-commit] Activate ruff checks and fix existing issues
2 parents bdfc5c8 + 233ab89 commit 5be64c3

31 files changed

+64
-67
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ select = [
133133
"F", # pyflakes
134134
"I", # isort
135135
"UP", # pyupgrade
136+
"RUF", # ruff
136137
"W", # pycodestyle
137138
]
138139
ignore = [
@@ -156,6 +157,8 @@ ignore = [
156157
"D402", # First line should not be the function's signature
157158
"D404", # First word of the docstring should not be "This"
158159
"D415", # First line should end with a period, question mark, or exclamation point
160+
# ruff ignore
161+
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
159162
]
160163

161164
[tool.ruff.format]

scripts/release.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def pre_release(
107107

108108
def changelog(version: str, write_out: bool = False) -> None:
109109
addopts = [] if write_out else ["--draft"]
110-
check_call(["towncrier", "--yes", "--version", version] + addopts)
110+
check_call(["towncrier", "--yes", "--version", version, *addopts])
111111

112112

113113
def main() -> None:

src/_pytest/_code/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ def _truncate_recursive_traceback(
10181018
extraline: Optional[str] = (
10191019
"!!! Recursion error detected, but an error occurred locating the origin of recursion.\n"
10201020
" The following exception happened when comparing locals in the stack frame:\n"
1021-
f" {type(e).__name__}: {str(e)}\n"
1021+
f" {type(e).__name__}: {e!s}\n"
10221022
f" Displaying first and last {max_frames} stack frames out of {len(traceback)}."
10231023
)
10241024
# Type ignored because adding two instances of a List subtype

src/_pytest/_py/path.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,9 +1105,7 @@ def pyimport(self, modname=None, ensuresyspath=True):
11051105
modname = self.purebasename
11061106
spec = importlib.util.spec_from_file_location(modname, str(self))
11071107
if spec is None or spec.loader is None:
1108-
raise ImportError(
1109-
f"Can't find module {modname} at location {str(self)}"
1110-
)
1108+
raise ImportError(f"Can't find module {modname} at location {self!s}")
11111109
mod = importlib.util.module_from_spec(spec)
11121110
spec.loader.exec_module(mod)
11131111
return mod

src/_pytest/assertion/rewrite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ def visit_Assert(self, assert_: ast.Assert) -> List[ast.stmt]:
925925
# If any hooks implement assert_pass hook
926926
hook_impl_test = ast.If(
927927
self.helper("_check_if_assertion_pass_impl"),
928-
self.expl_stmts + [hook_call_pass],
928+
[*self.expl_stmts, hook_call_pass],
929929
[],
930930
)
931931
statements_pass = [hook_impl_test]

src/_pytest/assertion/truncate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ def _truncate_explanation(
9292
else:
9393
# Add proper ellipsis when we were able to fit a full line exactly
9494
truncated_explanation[-1] = "..."
95-
return truncated_explanation + [
95+
return [
96+
*truncated_explanation,
9697
"",
9798
f"...Full output truncated ({truncated_line_count} line"
9899
f"{'' if truncated_line_count == 1 else 's'} hidden), {USAGE_MSG}",

src/_pytest/assertion/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ def assertrepr_compare(
233233
return None
234234

235235
if explanation[0] != "":
236-
explanation = [""] + explanation
237-
return [summary] + explanation
236+
explanation = ["", *explanation]
237+
return [summary, *explanation]
238238

239239

240240
def _compare_eq_any(

src/_pytest/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# https://www.python.org/dev/peps/pep-0484/#support-for-singleton-types-in-unions
2828
class NotSetType(enum.Enum):
2929
token = 0
30-
NOTSET: Final = NotSetType.token # noqa: E305
30+
NOTSET: Final = NotSetType.token
3131
# fmt: on
3232

3333

src/_pytest/config/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ def directory_arg(path: str, optname: str) -> str:
238238
"helpconfig", # Provides -p.
239239
)
240240

241-
default_plugins = essential_plugins + (
241+
default_plugins = (
242+
*essential_plugins,
242243
"python",
243244
"terminal",
244245
"debugging",
@@ -671,7 +672,7 @@ def _importconftest(
671672
if dirpath in path.parents or path == dirpath:
672673
if mod in mods:
673674
raise AssertionError(
674-
f"While trying to load conftest path {str(conftestpath)}, "
675+
f"While trying to load conftest path {conftestpath!s}, "
675676
f"found that the module {mod} is already loaded with path {mod.__file__}. "
676677
"This is not supposed to happen. Please report this issue to pytest."
677678
)

src/_pytest/config/argparsing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def _getparser(self) -> "MyOptionParser":
122122
from _pytest._argcomplete import filescompleter
123123

124124
optparser = MyOptionParser(self, self.extra_info, prog=self.prog)
125-
groups = self._groups + [self._anonymous]
125+
groups = [*self._groups, self._anonymous]
126126
for group in groups:
127127
if group.options:
128128
desc = group.description or group.name

0 commit comments

Comments
 (0)