Skip to content

[pre-commit.ci] pre-commit autoupdate #12995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.7.4"
rev: "v0.8.0"
hooks:
- id: ruff
args: ["--fix"]
Expand Down
8 changes: 4 additions & 4 deletions src/_pytest/_code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
__all__ = [
"Code",
"ExceptionInfo",
"filter_traceback",
"Frame",
"getfslineno",
"getrawcode",
"Source",
"Traceback",
"TracebackEntry",
"Source",
"filter_traceback",
"getfslineno",
"getrawcode",
]
10 changes: 4 additions & 6 deletions src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ def repr_traceback_entry(
if short:
message = f"in {entry.name}"
else:
message = excinfo and excinfo.typename or ""
message = (excinfo and excinfo.typename) or ""
entry_path = entry.path
path = self._makepath(entry_path)
reprfileloc = ReprFileLocation(path, entry.lineno + 1, message)
Expand Down Expand Up @@ -1186,10 +1186,8 @@ def toterminal(self, tw: TerminalWriter) -> None:
entry.toterminal(tw)
if i < len(self.reprentries) - 1:
next_entry = self.reprentries[i + 1]
if (
entry.style == "long"
or entry.style == "short"
and next_entry.style == "long"
if entry.style == "long" or (
entry.style == "short" and next_entry.style == "long"
):
tw.sep(self.entrysep)

Expand Down Expand Up @@ -1373,7 +1371,7 @@ def getfslineno(obj: object) -> tuple[str | Path, int]:
except TypeError:
return "", -1

fspath = fn and absolutepath(fn) or ""
fspath = (fn and absolutepath(fn)) or ""
lineno = -1
if fspath:
try:
Expand Down
4 changes: 2 additions & 2 deletions src/_pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Sentinel:

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

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


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


Expand Down
4 changes: 2 additions & 2 deletions src/_pytest/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def repr(self, class_name: str) -> str:
return "<{} {} _old={} _state={!r} tmpfile={!r}>".format(
class_name,
self.name,
hasattr(self, "_old") and repr(self._old) or "<UNSET>",
(hasattr(self, "_old") and repr(self._old)) or "<UNSET>",
self._state,
self.tmpfile,
)
Expand All @@ -369,7 +369,7 @@ def __repr__(self) -> str:
return "<{} {} _old={} _state={!r} tmpfile={!r}>".format(
self.__class__.__name__,
self.name,
hasattr(self, "_old") and repr(self._old) or "<UNSET>",
(hasattr(self, "_old") and repr(self._old)) or "<UNSET>",
self._state,
self.tmpfile,
)
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class FuncFixtureInfo:
these are not reflected here.
"""

__slots__ = ("argnames", "initialnames", "names_closure", "name2fixturedefs")
__slots__ = ("argnames", "initialnames", "name2fixturedefs", "names_closure")

# Fixture names that the item requests directly by function parameters.
argnames: tuple[str, ...]
Expand Down
10 changes: 4 additions & 6 deletions src/_pytest/mark/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class TokenType(enum.Enum):

@dataclasses.dataclass(frozen=True)
class Token:
__slots__ = ("type", "value", "pos")
__slots__ = ("pos", "type", "value")
type: TokenType
value: str
pos: int
Expand All @@ -80,7 +80,7 @@ def __str__(self) -> str:


class Scanner:
__slots__ = ("tokens", "current")
__slots__ = ("current", "tokens")

def __init__(self, input: str) -> None:
self.tokens = self.lex(input)
Expand Down Expand Up @@ -238,10 +238,8 @@ def single_kwarg(s: Scanner) -> ast.keyword:
value: str | int | bool | None = value_token.value[1:-1] # strip quotes
else:
value_token = s.accept(TokenType.IDENT, reject=True)
if (
(number := value_token.value).isdigit()
or number.startswith("-")
and number[1:].isdigit()
if (number := value_token.value).isdigit() or (
number.startswith("-") and number[1:].isdigit()
):
value = int(number)
elif value_token.value in BUILTIN_MATCHERS:
Expand Down
8 changes: 3 additions & 5 deletions src/_pytest/mark/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def __getattr__(self, name: str) -> MarkDecorator:

@final
class NodeKeywords(MutableMapping[str, Any]):
__slots__ = ("node", "parent", "_markers")
__slots__ = ("_markers", "node", "parent")

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

def __contains__(self, key: object) -> bool:
return (
key in self._markers
or self.parent is not None
and key in self.parent.keywords
return key in self._markers or (
self.parent is not None and key in self.parent.keywords
)

def update( # type: ignore[override]
Expand Down
10 changes: 5 additions & 5 deletions src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ class Node(abc.ABC, metaclass=NodeMeta):
# Use __slots__ to make attribute access faster.
# Note that __dict__ is still available.
__slots__ = (
"__dict__",
"_nodeid",
"_store",
"config",
"name",
"parent",
"config",
"session",
"path",
"_nodeid",
"_store",
"__dict__",
"session",
)

def __init__(
Expand Down
8 changes: 4 additions & 4 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def _genfunctions(self, name: str, funcobj) -> Iterator[Function]:
assert modulecol is not None
module = modulecol.obj
clscol = self.getparent(Class)
cls = clscol and clscol.obj or None
cls = (clscol and clscol.obj) or None

definition = FunctionDefinition.from_parent(self, name=name, callobj=funcobj)
fixtureinfo = definition._fixtureinfo
Expand Down Expand Up @@ -849,12 +849,12 @@ class IdMaker:

__slots__ = (
"argnames",
"parametersets",
"config",
"func_name",
"idfn",
"ids",
"config",
"nodeid",
"func_name",
"parametersets",
)

# The argnames of the parametrization.
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ def teardown_exact(self, nextitem: Item | None) -> None:
When nextitem is None (meaning we're at the last item), the entire
stack is torn down.
"""
needed_collectors = nextitem and nextitem.listchain() or []
needed_collectors = (nextitem and nextitem.listchain()) or []
exceptions: list[BaseException] = []
while self.stack:
if list(self.stack.keys()) == needed_collectors[: len(self.stack)]:
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def evaluate_skip_marks(item: Item) -> Skip | None:
class Xfail:
"""The result of evaluate_xfail_marks()."""

__slots__ = ("reason", "run", "strict", "raises")
__slots__ = ("raises", "reason", "run", "strict")

reason: str
run: bool
Expand Down
50 changes: 25 additions & 25 deletions src/pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,41 +88,27 @@


__all__ = [
"__version__",
"approx",
"Cache",
"CallInfo",
"CaptureFixture",
"Class",
"cmdline",
"Collector",
"CollectReport",
"Collector",
"Config",
"console_main",
"deprecated_call",
"Dir",
"Directory",
"DoctestItem",
"exit",
"ExceptionInfo",
"ExitCode",
"fail",
"File",
"fixture",
"FixtureDef",
"FixtureLookupError",
"FixtureRequest",
"freeze_includes",
"Function",
"hookimpl",
"HookRecorder",
"hookspec",
"importorskip",
"Item",
"LineMatcher",
"LogCaptureFixture",
"main",
"mark",
"Mark",
"MarkDecorator",
"MarkGenerator",
Expand All @@ -131,39 +117,53 @@
"MonkeyPatch",
"OptionGroup",
"Package",
"param",
"Parser",
"PytestAssertRewriteWarning",
"PytestCacheWarning",
"PytestCollectionWarning",
"PytestConfigWarning",
"PytestDeprecationWarning",
"PytestExperimentalApiWarning",
"PytestRemovedIn9Warning",
"Pytester",
"PytestPluginManager",
"PytestRemovedIn9Warning",
"PytestUnhandledThreadExceptionWarning",
"PytestUnknownMarkWarning",
"PytestUnraisableExceptionWarning",
"PytestWarning",
"raises",
"Pytester",
"RecordedHookCall",
"register_assert_rewrite",
"RunResult",
"Session",
"set_trace",
"skip",
"Stash",
"StashKey",
"version_tuple",
"TempdirFactory",
"TempPathFactory",
"TempdirFactory",
"TerminalReporter",
"Testdir",
"TestReport",
"TestShortLogReport",
"Testdir",
"UsageError",
"WarningsRecorder",
"__version__",
"approx",
"cmdline",
"console_main",
"deprecated_call",
"exit",
"fail",
"fixture",
"freeze_includes",
"hookimpl",
"hookspec",
"importorskip",
"main",
"mark",
"param",
"raises",
"register_assert_rewrite",
"set_trace",
"skip",
"version_tuple",
"warns",
"xfail",
"yield_fixture",
Expand Down
4 changes: 2 additions & 2 deletions testing/_py/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@
assert b.fnmatch(pattern)

def test_sysfind(self):
name = sys.platform == "win32" and "cmd" or "test"
name = (sys.platform == "win32" and "cmd") or "test"
x = local.sysfind(name)
assert x.check(file=1)
assert local.sysfind("jaksdkasldqwe") is None
Expand Down Expand Up @@ -1250,7 +1250,7 @@
def test_chmod_simple_int(self, path1):
mode = path1.stat().mode
# Ensure that we actually change the mode to something different.
path1.chmod(mode == 0 and 1 or 0)
path1.chmod((mode == 0 and 1) or 0)

Check warning on line 1253 in testing/_py/test_local.py

View check run for this annotation

Codecov / codecov/patch

testing/_py/test_local.py#L1253

Added line #L1253 was not covered by tests
try:
print(path1.stat().mode)
print(mode)
Expand Down
Loading