Skip to content

Commit 10bcc70

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

15 files changed

+61
-65
lines changed

.pre-commit-config.yaml

+1-1
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

+2
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

+4-4
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

+4-6
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

+2-2
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

+2-2
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

+1-1
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

+4-6
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

+3-5
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

+5-5
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__(

src/_pytest/python.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def _genfunctions(self, name: str, funcobj) -> Iterator[Function]:
431431
assert modulecol is not None
432432
module = modulecol.obj
433433
clscol = self.getparent(Class)
434-
cls = clscol and clscol.obj or None
434+
cls = (clscol and clscol.obj) or None
435435

436436
definition = FunctionDefinition.from_parent(self, name=name, callobj=funcobj)
437437
fixtureinfo = definition._fixtureinfo
@@ -848,12 +848,12 @@ class IdMaker:
848848

849849
__slots__ = (
850850
"argnames",
851-
"parametersets",
851+
"config",
852+
"func_name",
852853
"idfn",
853854
"ids",
854-
"config",
855855
"nodeid",
856-
"func_name",
856+
"parametersets",
857857
)
858858

859859
# The argnames of the parametrization.

src/_pytest/runner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def teardown_exact(self, nextitem: Item | None) -> None:
533533
When nextitem is None (meaning we're at the last item), the entire
534534
stack is torn down.
535535
"""
536-
needed_collectors = nextitem and nextitem.listchain() or []
536+
needed_collectors = (nextitem and nextitem.listchain()) or []
537537
exceptions: list[BaseException] = []
538538
while self.stack:
539539
if list(self.stack.keys()) == needed_collectors[: len(self.stack)]:

src/_pytest/skipping.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def evaluate_skip_marks(item: Item) -> Skip | None:
196196
class Xfail:
197197
"""The result of evaluate_xfail_marks()."""
198198

199-
__slots__ = ("reason", "run", "strict", "raises")
199+
__slots__ = ("raises", "reason", "run", "strict")
200200

201201
reason: str
202202
run: bool

src/pytest/__init__.py

+25-25
Original file line numberDiff line numberDiff line change
@@ -88,41 +88,27 @@
8888

8989

9090
__all__ = [
91-
"__version__",
92-
"approx",
9391
"Cache",
9492
"CallInfo",
9593
"CaptureFixture",
9694
"Class",
97-
"cmdline",
98-
"Collector",
9995
"CollectReport",
96+
"Collector",
10097
"Config",
101-
"console_main",
102-
"deprecated_call",
10398
"Dir",
10499
"Directory",
105100
"DoctestItem",
106-
"exit",
107101
"ExceptionInfo",
108102
"ExitCode",
109-
"fail",
110103
"File",
111-
"fixture",
112104
"FixtureDef",
113105
"FixtureLookupError",
114106
"FixtureRequest",
115-
"freeze_includes",
116107
"Function",
117-
"hookimpl",
118108
"HookRecorder",
119-
"hookspec",
120-
"importorskip",
121109
"Item",
122110
"LineMatcher",
123111
"LogCaptureFixture",
124-
"main",
125-
"mark",
126112
"Mark",
127113
"MarkDecorator",
128114
"MarkGenerator",
@@ -131,39 +117,53 @@
131117
"MonkeyPatch",
132118
"OptionGroup",
133119
"Package",
134-
"param",
135120
"Parser",
136121
"PytestAssertRewriteWarning",
137122
"PytestCacheWarning",
138123
"PytestCollectionWarning",
139124
"PytestConfigWarning",
140125
"PytestDeprecationWarning",
141126
"PytestExperimentalApiWarning",
142-
"PytestRemovedIn9Warning",
143-
"Pytester",
144127
"PytestPluginManager",
128+
"PytestRemovedIn9Warning",
145129
"PytestUnhandledThreadExceptionWarning",
146130
"PytestUnknownMarkWarning",
147131
"PytestUnraisableExceptionWarning",
148132
"PytestWarning",
149-
"raises",
133+
"Pytester",
150134
"RecordedHookCall",
151-
"register_assert_rewrite",
152135
"RunResult",
153136
"Session",
154-
"set_trace",
155-
"skip",
156137
"Stash",
157138
"StashKey",
158-
"version_tuple",
159-
"TempdirFactory",
160139
"TempPathFactory",
140+
"TempdirFactory",
161141
"TerminalReporter",
162-
"Testdir",
163142
"TestReport",
164143
"TestShortLogReport",
144+
"Testdir",
165145
"UsageError",
166146
"WarningsRecorder",
147+
"__version__",
148+
"approx",
149+
"cmdline",
150+
"console_main",
151+
"deprecated_call",
152+
"exit",
153+
"fail",
154+
"fixture",
155+
"freeze_includes",
156+
"hookimpl",
157+
"hookspec",
158+
"importorskip",
159+
"main",
160+
"mark",
161+
"param",
162+
"raises",
163+
"register_assert_rewrite",
164+
"set_trace",
165+
"skip",
166+
"version_tuple",
167167
"warns",
168168
"xfail",
169169
"yield_fixture",

testing/_py/test_local.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ def test_fnmatch_file_abspath(self, tmpdir):
855855
assert b.fnmatch(pattern)
856856

857857
def test_sysfind(self):
858-
name = sys.platform == "win32" and "cmd" or "test"
858+
name = (sys.platform == "win32" and "cmd") or "test"
859859
x = local.sysfind(name)
860860
assert x.check(file=1)
861861
assert local.sysfind("jaksdkasldqwe") is None
@@ -1250,7 +1250,7 @@ def test_owner_group_not_implemented(self, path1):
12501250
def test_chmod_simple_int(self, path1):
12511251
mode = path1.stat().mode
12521252
# Ensure that we actually change the mode to something different.
1253-
path1.chmod(mode == 0 and 1 or 0)
1253+
path1.chmod((mode == 0 and 1) or 0)
12541254
try:
12551255
print(path1.stat().mode)
12561256
print(mode)

0 commit comments

Comments
 (0)