Skip to content

Commit 475b9c7

Browse files
[pre-commit] Upgrade ruff to 0.9.0 / 2025's style
1 parent 3432c20 commit 475b9c7

File tree

16 files changed

+103
-101
lines changed

16 files changed

+103
-101
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: "v0.8.6"
3+
rev: "v0.9.0"
44
hooks:
55
- id: ruff
66
args: ["--fix"]

doc/en/example/assertion/failure_demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ class A:
267267
a = 1
268268

269269
b = 2
270-
assert (
271-
A.a == b
272-
), "A.a appears not to be b\nor does not appear to be b\none of those"
270+
assert A.a == b, (
271+
"A.a appears not to be b\nor does not appear to be b\none of those"
272+
)
273273

274274
def test_custom_repr(self):
275275
class JSON:

scripts/prepare-release-pr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def find_next_version(
163163
last_version = valid_versions[-1]
164164

165165
if is_major:
166-
return f"{last_version[0]+1}.0.0{prerelease}"
166+
return f"{last_version[0] + 1}.0.0{prerelease}"
167167
elif is_feature_release:
168168
return f"{last_version[0]}.{last_version[1] + 1}.0{prerelease}"
169169
else:

scripts/update-plugin-list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def version_sort_key(version_string: str) -> Any:
176176
)
177177
last_release = release_date.strftime("%b %d, %Y")
178178
break
179-
name = f':pypi:`{info["name"]}`'
179+
name = f":pypi:`{info['name']}`"
180180
summary = ""
181181
if info["summary"]:
182182
summary = escape_rst(info["summary"].replace("\n", ""))
@@ -194,7 +194,7 @@ def plugin_definitions(plugins: Iterable[PluginInfo]) -> Iterator[str]:
194194
for plugin in plugins:
195195
yield dedent(
196196
f"""
197-
{plugin['name']}
197+
{plugin["name"]}
198198
*last release*: {plugin["last_release"]},
199199
*status*: {plugin["status"]},
200200
*requires*: {plugin["requires"]}

src/_pytest/_code/code.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def relline(self) -> int:
217217
return self.lineno - self.frame.code.firstlineno
218218

219219
def __repr__(self) -> str:
220-
return f"<TracebackEntry {self.frame.code.path}:{self.lineno+1}>"
220+
return f"<TracebackEntry {self.frame.code.path}:{self.lineno + 1}>"
221221

222222
@property
223223
def statement(self) -> Source:
@@ -303,7 +303,7 @@ def __str__(self) -> str:
303303
# This output does not quite match Python's repr for traceback entries,
304304
# but changing it to do so would break certain plugins. See
305305
# https://github.com/pytest-dev/pytest/pull/7535/ for details.
306-
return f" File '{self.path}':{self.lineno+1} in {name}\n {line}\n"
306+
return f" File '{self.path}':{self.lineno + 1} in {name}\n {line}\n"
307307

308308
@property
309309
def name(self) -> str:
@@ -527,33 +527,33 @@ def fill_unfilled(self, exc_info: tuple[type[E], E, TracebackType]) -> None:
527527
@property
528528
def type(self) -> type[E]:
529529
"""The exception class."""
530-
assert (
531-
self._excinfo is not None
532-
), ".type can only be used after the context manager exits"
530+
assert self._excinfo is not None, (
531+
".type can only be used after the context manager exits"
532+
)
533533
return self._excinfo[0]
534534

535535
@property
536536
def value(self) -> E:
537537
"""The exception value."""
538-
assert (
539-
self._excinfo is not None
540-
), ".value can only be used after the context manager exits"
538+
assert self._excinfo is not None, (
539+
".value can only be used after the context manager exits"
540+
)
541541
return self._excinfo[1]
542542

543543
@property
544544
def tb(self) -> TracebackType:
545545
"""The exception raw traceback."""
546-
assert (
547-
self._excinfo is not None
548-
), ".tb can only be used after the context manager exits"
546+
assert self._excinfo is not None, (
547+
".tb can only be used after the context manager exits"
548+
)
549549
return self._excinfo[2]
550550

551551
@property
552552
def typename(self) -> str:
553553
"""The type name of the exception."""
554-
assert (
555-
self._excinfo is not None
556-
), ".typename can only be used after the context manager exits"
554+
assert self._excinfo is not None, (
555+
".typename can only be used after the context manager exits"
556+
)
557557
return self.type.__name__
558558

559559
@property

src/_pytest/cacheprovider.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,7 @@ def pytest_addoption(parser: Parser) -> None:
482482
"--last-failed",
483483
action="store_true",
484484
dest="lf",
485-
help="Rerun only the tests that failed "
486-
"at the last run (or all if none failed)",
485+
help="Rerun only the tests that failed at the last run (or all if none failed)",
487486
)
488487
group.addoption(
489488
"--ff",

src/_pytest/capture.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,10 @@ def __repr__(self) -> str:
375375
)
376376

377377
def _assert_state(self, op: str, states: tuple[str, ...]) -> None:
378-
assert (
379-
self._state in states
380-
), "cannot {} in state {!r}: expected one of {}".format(
381-
op, self._state, ", ".join(states)
378+
assert self._state in states, (
379+
"cannot {} in state {!r}: expected one of {}".format(
380+
op, self._state, ", ".join(states)
381+
)
382382
)
383383

384384
def start(self) -> None:
@@ -492,10 +492,10 @@ def __repr__(self) -> str:
492492
)
493493

494494
def _assert_state(self, op: str, states: tuple[str, ...]) -> None:
495-
assert (
496-
self._state in states
497-
), "cannot {} in state {!r}: expected one of {}".format(
498-
op, self._state, ", ".join(states)
495+
assert self._state in states, (
496+
"cannot {} in state {!r}: expected one of {}".format(
497+
op, self._state, ", ".join(states)
498+
)
499499
)
500500

501501
def start(self) -> None:

src/_pytest/compat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ def getlocation(function, curdir: str | os.PathLike[str] | None = None) -> str:
7070
except ValueError:
7171
pass
7272
else:
73-
return f"{relfn}:{lineno+1}"
74-
return f"{fn}:{lineno+1}"
73+
return f"{relfn}:{lineno + 1}"
74+
return f"{fn}:{lineno + 1}"
7575

7676

7777
def num_mock_patch_args(function) -> int:

src/_pytest/config/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -838,9 +838,9 @@ def import_plugin(self, modname: str, consider_entry_points: bool = False) -> No
838838
# "terminal" or "capture". Those plugins are registered under their
839839
# basename for historic purposes but must be imported with the
840840
# _pytest prefix.
841-
assert isinstance(
842-
modname, str
843-
), f"module name as text required, got {modname!r}"
841+
assert isinstance(modname, str), (
842+
f"module name as text required, got {modname!r}"
843+
)
844844
if self.is_blocked(modname) or self.get_plugin(modname) is not None:
845845
return
846846

@@ -1503,9 +1503,9 @@ def _get_unknown_ini_keys(self) -> list[str]:
15031503

15041504
def parse(self, args: list[str], addopts: bool = True) -> None:
15051505
# Parse given cmdline arguments into this config object.
1506-
assert (
1507-
self.args == []
1508-
), "can only parse cmdline args at most once per Config object"
1506+
assert self.args == [], (
1507+
"can only parse cmdline args at most once per Config object"
1508+
)
15091509
self.hook.pytest_addhooks.call_historic(
15101510
kwargs=dict(pluginmanager=self.pluginmanager)
15111511
)

src/_pytest/fixtures.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,9 @@ def node(self):
746746
if node is None and scope is Scope.Class:
747747
# Fallback to function item itself.
748748
node = self._pyfuncitem
749-
assert node, f'Could not obtain a node for scope "{scope}" for function {self._pyfuncitem!r}'
749+
assert node, (
750+
f'Could not obtain a node for scope "{scope}" for function {self._pyfuncitem!r}'
751+
)
750752
return node
751753

752754
def _check_scope(
@@ -808,9 +810,9 @@ def formatrepr(self) -> FixtureLookupErrorRepr:
808810
# new cases it might break.
809811
# Add the assert to make it clearer to developer that this will fail, otherwise
810812
# it crashes because `fspath` does not get set due to `stack` being empty.
811-
assert (
812-
self.msg is None or self.fixturestack
813-
), "formatrepr assumptions broken, rewrite it to handle it"
813+
assert self.msg is None or self.fixturestack, (
814+
"formatrepr assumptions broken, rewrite it to handle it"
815+
)
814816
if msg is not None:
815817
# The last fixture raise an error, let's present
816818
# it at the requesting side.

0 commit comments

Comments
 (0)