Skip to content

Commit 10bcc70

Browse files
[pre-commit] Upgrade ruff to 0.8.1
1 parent d65d991 commit 10bcc70

File tree

15 files changed

+61
-65
lines changed

15 files changed

+61
-65
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.7.4"
3+
rev: "v0.8.1"
44
hooks:
55
- id: ruff
66
args: ["--fix"]

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,10 @@ lint.ignore = [
156156
"PLW0120", # remove the else and dedent its contents
157157
"PLW0603", # Using the global statement
158158
"PLW2901", # for loop variable overwritten by assignment target
159+
"PYI063",
159160
# ruff ignore
160161
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
162+
"UP031",
161163
]
162164
lint.per-file-ignores."src/_pytest/_py/**/*.py" = [
163165
"B",

src/_pytest/_code/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
__all__ = [
1717
"Code",
1818
"ExceptionInfo",
19-
"filter_traceback",
2019
"Frame",
21-
"getfslineno",
22-
"getrawcode",
20+
"Source",
2321
"Traceback",
2422
"TracebackEntry",
25-
"Source",
23+
"filter_traceback",
24+
"getfslineno",
25+
"getrawcode",
2626
]

src/_pytest/_code/code.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ def repr_traceback_entry(
953953
if short:
954954
message = f"in {entry.name}"
955955
else:
956-
message = excinfo and excinfo.typename or ""
956+
message = (excinfo and excinfo.typename) or ""
957957
entry_path = entry.path
958958
path = self._makepath(entry_path)
959959
reprfileloc = ReprFileLocation(path, entry.lineno + 1, message)
@@ -1182,10 +1182,8 @@ def toterminal(self, tw: TerminalWriter) -> None:
11821182
entry.toterminal(tw)
11831183
if i < len(self.reprentries) - 1:
11841184
next_entry = self.reprentries[i + 1]
1185-
if (
1186-
entry.style == "long"
1187-
or entry.style == "short"
1188-
and next_entry.style == "long"
1185+
if entry.style == "long" or (
1186+
entry.style == "short" and next_entry.style == "long"
11891187
):
11901188
tw.sep(self.entrysep)
11911189

@@ -1369,7 +1367,7 @@ def getfslineno(obj: object) -> tuple[str | Path, int]:
13691367
except TypeError:
13701368
return "", -1
13711369

1372-
fspath = fn and absolutepath(fn) or ""
1370+
fspath = (fn and absolutepath(fn)) or ""
13731371
lineno = -1
13741372
if fspath:
13751373
try:

src/_pytest/assertion/rewrite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Sentinel:
5353

5454
# pytest caches rewritten pycs in pycache dirs
5555
PYTEST_TAG = f"{sys.implementation.cache_tag}-pytest-{version}"
56-
PYC_EXT = ".py" + (__debug__ and "c" or "o")
56+
PYC_EXT = ".py" + ((__debug__ and "c") or "o")
5757
PYC_TAIL = "." + PYTEST_TAG + PYC_EXT
5858

5959
# Special marker that denotes we have just left a scope definition
@@ -481,7 +481,7 @@ def _should_repr_global_name(obj: object) -> bool:
481481

482482

483483
def _format_boolop(explanations: Iterable[str], is_or: bool) -> str:
484-
explanation = "(" + (is_or and " or " or " and ").join(explanations) + ")"
484+
explanation = "(" + ((is_or and " or ") or " and ").join(explanations) + ")"
485485
return explanation.replace("%", "%%")
486486

487487

src/_pytest/capture.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def repr(self, class_name: str) -> str:
360360
return "<{} {} _old={} _state={!r} tmpfile={!r}>".format(
361361
class_name,
362362
self.name,
363-
hasattr(self, "_old") and repr(self._old) or "<UNSET>",
363+
(hasattr(self, "_old") and repr(self._old)) or "<UNSET>",
364364
self._state,
365365
self.tmpfile,
366366
)
@@ -369,7 +369,7 @@ def __repr__(self) -> str:
369369
return "<{} {} _old={} _state={!r} tmpfile={!r}>".format(
370370
self.__class__.__name__,
371371
self.name,
372-
hasattr(self, "_old") and repr(self._old) or "<UNSET>",
372+
(hasattr(self, "_old") and repr(self._old)) or "<UNSET>",
373373
self._state,
374374
self.tmpfile,
375375
)

src/_pytest/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class FuncFixtureInfo:
305305
these are not reflected here.
306306
"""
307307

308-
__slots__ = ("argnames", "initialnames", "names_closure", "name2fixturedefs")
308+
__slots__ = ("argnames", "initialnames", "name2fixturedefs", "names_closure")
309309

310310
# Fixture names that the item requests directly by function parameters.
311311
argnames: tuple[str, ...]

src/_pytest/mark/expression.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class TokenType(enum.Enum):
5858

5959
@dataclasses.dataclass(frozen=True)
6060
class Token:
61-
__slots__ = ("type", "value", "pos")
61+
__slots__ = ("pos", "type", "value")
6262
type: TokenType
6363
value: str
6464
pos: int
@@ -80,7 +80,7 @@ def __str__(self) -> str:
8080

8181

8282
class Scanner:
83-
__slots__ = ("tokens", "current")
83+
__slots__ = ("current", "tokens")
8484

8585
def __init__(self, input: str) -> None:
8686
self.tokens = self.lex(input)
@@ -238,10 +238,8 @@ def single_kwarg(s: Scanner) -> ast.keyword:
238238
value: str | int | bool | None = value_token.value[1:-1] # strip quotes
239239
else:
240240
value_token = s.accept(TokenType.IDENT, reject=True)
241-
if (
242-
(number := value_token.value).isdigit()
243-
or number.startswith("-")
244-
and number[1:].isdigit()
241+
if (number := value_token.value).isdigit() or (
242+
number.startswith("-") and number[1:].isdigit()
245243
):
246244
value = int(number)
247245
elif value_token.value in BUILTIN_MATCHERS:

src/_pytest/mark/structures.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ def __getattr__(self, name: str) -> MarkDecorator:
562562

563563
@final
564564
class NodeKeywords(MutableMapping[str, Any]):
565-
__slots__ = ("node", "parent", "_markers")
565+
__slots__ = ("_markers", "node", "parent")
566566

567567
def __init__(self, node: Node) -> None:
568568
self.node = node
@@ -584,10 +584,8 @@ def __setitem__(self, key: str, value: Any) -> None:
584584
# below and use the collections.abc fallback, but that would be slow.
585585

586586
def __contains__(self, key: object) -> bool:
587-
return (
588-
key in self._markers
589-
or self.parent is not None
590-
and key in self.parent.keywords
587+
return key in self._markers or (
588+
self.parent is not None and key in self.parent.keywords
591589
)
592590

593591
def update( # type: ignore[override]

src/_pytest/nodes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ class Node(abc.ABC, metaclass=NodeMeta):
143143
# Use __slots__ to make attribute access faster.
144144
# Note that __dict__ is still available.
145145
__slots__ = (
146+
"__dict__",
147+
"_nodeid",
148+
"_store",
149+
"config",
146150
"name",
147151
"parent",
148-
"config",
149-
"session",
150152
"path",
151-
"_nodeid",
152-
"_store",
153-
"__dict__",
153+
"session",
154154
)
155155

156156
def __init__(

0 commit comments

Comments
 (0)