Skip to content

Commit 17c5bbb

Browse files
[Fix UP031] Manually, keeping some required %r specifiers
Co-authored-by: Bruno Oliveira <[email protected]>
1 parent 049bb29 commit 17c5bbb

21 files changed

+53
-72
lines changed

bench/empty.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33

44
for i in range(1000):
5-
exec("def test_func_%d(): pass" % i)
5+
exec(f"def test_func_{i}(): pass")

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ lint.ignore = [
158158
"PLW2901", # for loop variable overwritten by assignment target
159159
# ruff ignore
160160
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
161-
"UP031",
162161
]
163162
lint.per-file-ignores."src/_pytest/_py/**/*.py" = [
164163
"B",

src/_pytest/_code/code.py

Lines changed: 2 additions & 7 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 "<TracebackEntry %s:%d>" % (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,12 +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 " File %r:%d in %s\n %s\n" % (
307-
str(self.path),
308-
self.lineno + 1,
309-
name,
310-
line,
311-
)
306+
return f" File '{self.path}':{self.lineno+1} in {name}\n {line}\n"
312307

313308
@property
314309
def name(self) -> str:

src/_pytest/_io/pprint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ def _pprint_deque(
540540
) -> None:
541541
stream.write(object.__class__.__name__ + "(")
542542
if object.maxlen is not None:
543-
stream.write("maxlen=%d, " % object.maxlen)
543+
stream.write(f"maxlen={object.maxlen}, ")
544544
stream.write("[")
545545

546546
self._format_items(object, stream, indent, allowance + 1, context, level)

src/_pytest/_py/error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def _geterrnoclass(self, eno: int) -> type[Error]:
6969
try:
7070
return self._errno2class[eno]
7171
except KeyError:
72-
clsname = errno.errorcode.get(eno, "UnknownErrno%d" % (eno,))
72+
clsname = errno.errorcode.get(eno, f"UnknownErrno{eno}")
7373
errorcls = type(
7474
clsname,
7575
(Error,),

src/_pytest/assertion/util.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,7 @@ def _compare_eq_sequence(
406406
]
407407
else:
408408
explanation += [
409-
"%s contains %d more items, first extra item: %s"
410-
% (dir_with_more, len_diff, highlighter(extra))
409+
f"{dir_with_more} contains {len_diff} more items, first extra item: {highlighter(extra)}"
411410
]
412411
return explanation
413412

@@ -510,8 +509,7 @@ def _compare_eq_dict(
510509
len_extra_left = len(extra_left)
511510
if len_extra_left:
512511
explanation.append(
513-
"Left contains %d more item%s:"
514-
% (len_extra_left, "" if len_extra_left == 1 else "s")
512+
f"Left contains {len_extra_left} more item{'' if len_extra_left == 1 else 's'}:"
515513
)
516514
explanation.extend(
517515
highlighter(pprint.pformat({k: left[k] for k in extra_left})).splitlines()
@@ -520,8 +518,7 @@ def _compare_eq_dict(
520518
len_extra_right = len(extra_right)
521519
if len_extra_right:
522520
explanation.append(
523-
"Right contains %d more item%s:"
524-
% (len_extra_right, "" if len_extra_right == 1 else "s")
521+
f"Right contains {len_extra_right} more item{'' if len_extra_right == 1 else 's'}:"
525522
)
526523
explanation.extend(
527524
highlighter(pprint.pformat({k: right[k] for k in extra_right})).splitlines()

src/_pytest/cacheprovider.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ def pytest_collection_modifyitems(
388388
if not previously_failed:
389389
# Running a subset of all tests with recorded failures
390390
# only outside of it.
391-
self._report_status = "%d known failures not in selected tests" % (
392-
len(self.lastfailed),
391+
self._report_status = (
392+
f"{len(self.lastfailed)} known failures not in selected tests"
393393
)
394394
else:
395395
if self.config.getoption("lf"):
@@ -622,5 +622,5 @@ def cacheshow(config: Config, session: Session) -> int:
622622
# print("%s/" % p.relative_to(basedir))
623623
if p.is_file():
624624
key = str(p.relative_to(basedir))
625-
tw.line(f"{key} is a file of length {p.stat().st_size:d}")
625+
tw.line(f"{key} is a file of length {p.stat().st_size}")
626626
return 0

src/_pytest/compat.py

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

7777

7878
def num_mock_patch_args(function) -> int:

src/_pytest/doctest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def repr_failure( # type: ignore[override]
353353
# add line numbers to the left of the error message
354354
assert test.lineno is not None
355355
lines = [
356-
"%03d %s" % (i + test.lineno + 1, x) for (i, x) in enumerate(lines)
356+
f"{i + test.lineno + 1:03d} {x}" for (i, x) in enumerate(lines)
357357
]
358358
# trim docstring error lines to 10
359359
lines = lines[max(example.lineno - 9, 0) : example.lineno + 1]

src/_pytest/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ def toterminal(self, tw: TerminalWriter) -> None:
884884
red=True,
885885
)
886886
tw.line()
887-
tw.line("%s:%d" % (os.fspath(self.filename), self.firstlineno + 1))
887+
tw.line(f"{os.fspath(self.filename)}:{self.firstlineno + 1}")
888888

889889

890890
def call_fixture_func(

0 commit comments

Comments
 (0)