From f86f2879e1fc74aa6b8db493b24a321711414565 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Jul 2026 21:10:17 +0000 Subject: [PATCH] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.15.22 → v0.16.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.15.22...v0.16.0) - [github.com/woodruffw/zizmor-pre-commit: v1.27.0 → v1.28.0](https://github.com/woodruffw/zizmor-pre-commit/compare/v1.27.0...v1.28.0) --- .pre-commit-config.yaml | 4 ++-- doc/en/example/.ruff.toml | 1 - pyproject.toml | 12 ++++++++++-- src/_pytest/config/__init__.py | 4 ++-- src/_pytest/fixtures.py | 8 ++++---- src/_pytest/hookspec.py | 2 +- src/_pytest/mark/structures.py | 8 ++++---- src/_pytest/python.py | 2 +- src/_pytest/reports.py | 18 +++++++++--------- src/_pytest/runner.py | 2 +- src/_pytest/terminal.py | 2 +- testing/python/metafunc.py | 2 +- 12 files changed, 36 insertions(+), 29 deletions(-) delete mode 100644 doc/en/example/.ruff.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1f3e8f3bd53..1b40df3f0cd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ minimum_pre_commit_version: "4.4.0" repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.15.22" + rev: "v0.16.0" hooks: - id: ruff-check args: ["--fix"] @@ -13,7 +13,7 @@ repos: - id: end-of-file-fixer - id: check-yaml - repo: https://github.com/woodruffw/zizmor-pre-commit - rev: v1.27.0 + rev: v1.28.0 hooks: - id: zizmor args: ["--fix", "--no-progress"] diff --git a/doc/en/example/.ruff.toml b/doc/en/example/.ruff.toml deleted file mode 100644 index feddc5c0654..00000000000 --- a/doc/en/example/.ruff.toml +++ /dev/null @@ -1 +0,0 @@ -lint.ignore = ["RUF059"] diff --git a/pyproject.toml b/pyproject.toml index a0e2c40f4d4..b467ed0fba0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -171,6 +171,7 @@ lint.ignore = [ "PLR0912", # Too many branches "PLR0913", # Too many arguments in function definition "PLR0915", # Too many statements + "PLR0917", # Too many positional arguments "PLR2004", # Magic value used in comparison "PLR2044", # Line with empty comment "PLR5501", # Use `elif` instead of `else` then `if` @@ -182,6 +183,12 @@ lint.ignore = [ "RUF012", # Mutable class attributes should be annotated with `typing.ClassVar` "RUF061", # Use context-manager form of `pytest.raises()` ] +lint.per-file-ignores."doc/**/*.py" = [ + "PLR0133", # Two constants compared in a comparison, + "RUF059", # Unpacked variable is never used + "S102", # Use of `exec` detected + "TRY002", # Create your own exception +] lint.per-file-ignores."src/_pytest/_py/**/*.py" = [ "B", "PYI", @@ -189,8 +196,9 @@ lint.per-file-ignores."src/_pytest/_py/**/*.py" = [ lint.per-file-ignores."src/_pytest/_version.py" = [ "I001", ] -# 'Unnecessary membership test on empty collection', always voluntary in tests -lint.per-file-ignores."testing/**/*.py" = [ "RUF060" ] +lint.per-file-ignores."testing/**/*.py" = [ + "RUF060", # 'Unnecessary membership test on empty collection', always voluntary in tests +] # can't be disabled on a line-by-line basis in file lint.per-file-ignores."testing/code/test_source.py" = [ "F841", diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index c5f75cebcb5..6f30406c386 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -881,7 +881,7 @@ def consider_module(self, mod: types.ModuleType) -> None: self._import_plugin_specs(getattr(mod, "pytest_plugins", [])) def _import_plugin_specs( - self, spec: None | types.ModuleType | str | Sequence[str] + self, spec: types.ModuleType | str | Sequence[str] | None ) -> None: plugins = _get_plugin_specs_as_list(spec) for import_spec in plugins: @@ -931,7 +931,7 @@ def import_plugin(self, modname: str, consider_entry_points: bool = False) -> No def _get_plugin_specs_as_list( - specs: None | types.ModuleType | str | Sequence[str], + specs: types.ModuleType | str | Sequence[str] | None, ) -> list[str]: """Parse a plugins specification into a list of plugin names.""" # None means empty. diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 1b1591d1f83..44c304905e7 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -1118,7 +1118,7 @@ class FixtureDef(Generic[FixtureValue]): def __init__( self, config: Config, - baseid: str | None | NotSetType, + baseid: str | NotSetType | None, argname: str, func: _FixtureFunc[FixtureValue], scope: Scope | ScopeName | Callable[[str, Config], ScopeName] | None, @@ -2049,7 +2049,7 @@ def _register_fixture( *, name: str, func: _FixtureFunc[object], - nodeid: str | None | NotSetType = NOTSET, + nodeid: str | NotSetType | None = NOTSET, scope: Scope | ScopeName | Callable[[str, Config], ScopeName] = "function", params: Sequence[object] | None = None, ids: tuple[object | None, ...] | Callable[[Any], object | None] | None = None, @@ -2247,7 +2247,7 @@ def parsefactories( def parsefactories( self, node_or_obj: nodes.Node | object | NotSetType = NOTSET, - nodeid: str | None | NotSetType = NOTSET, + nodeid: str | NotSetType | None = NOTSET, *, holder: object | NotSetType = NOTSET, node: nodes.Node | NotSetType = NOTSET, @@ -2267,7 +2267,7 @@ def parsefactories( # Translate legacy API to holder/node sources of truth # Either effective_node or effective_nodeid will be set, not both effective_node: nodes.Node | NotSetType = NOTSET - effective_nodeid: str | None | NotSetType = NOTSET + effective_nodeid: str | NotSetType | None = NOTSET if holder is not NOTSET: # New API: holder and node explicitly provided diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index ba7ac2b76e3..350b333144a 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -508,7 +508,7 @@ def pytest_pycollect_makemodule(module_path: Path, parent) -> Module | None: @hookspec(firstresult=True) def pytest_pycollect_makeitem( collector: Module | Class, name: str, obj: object -) -> None | Item | Collector | list[Item | Collector]: +) -> Item | Collector | list[Item | Collector] | None: """Return a custom item/collector for a Python object in a module, or None. Stops at first non-None result, see :ref:`firstresult`. diff --git a/src/_pytest/mark/structures.py b/src/_pytest/mark/structures.py index e14e1406336..18057f0b0ff 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -531,10 +531,10 @@ def __call__( *conditions: str | bool, reason: str = ..., run: bool = ..., - raises: None - | type[BaseException] + raises: type[BaseException] | tuple[type[BaseException], ...] - | AbstractRaises[BaseException] = ..., + | AbstractRaises[BaseException] + | None = ..., strict: bool = ..., ) -> MarkDecorator: ... @@ -548,7 +548,7 @@ def __call__( # type: ignore[override] # argvalues: Collection[ParameterSet | Sequence[object] | object], *, indirect: bool | Sequence[str] = ..., - ids: Iterable[None | str | float | int | bool | _HiddenParam] + ids: Iterable[str | float | int | bool | _HiddenParam | None] | Callable[[Any], object | None] | None = ..., scope: ScopeName | None = ..., diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 4f168012c36..03bf8327c6c 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -238,7 +238,7 @@ def pytest_pycollect_makemodule(module_path: Path, parent) -> Module: @hookimpl(trylast=True) def pytest_pycollect_makeitem( collector: Module | Class, name: str, obj: object -) -> None | nodes.Item | nodes.Collector | list[nodes.Item | nodes.Collector]: +) -> nodes.Item | nodes.Collector | list[nodes.Item | nodes.Collector] | None: assert isinstance(collector, Class | Module), type(collector) # Nothing was collected elsewhere, let's do it here. if safe_isclass(obj): diff --git a/src/_pytest/reports.py b/src/_pytest/reports.py index 011a69db001..72fe10e96c7 100644 --- a/src/_pytest/reports.py +++ b/src/_pytest/reports.py @@ -62,7 +62,7 @@ class BaseReport: when: str | None location: tuple[str, int | None, str] | None longrepr: ( - None | ExceptionInfo[BaseException] | tuple[str, int, str] | str | TerminalRepr + ExceptionInfo[BaseException] | tuple[str, int, str] | str | TerminalRepr | None ) sections: list[tuple[str, str]] nodeid: str @@ -321,11 +321,11 @@ def __init__( location: tuple[str, int | None, str], keywords: Mapping[str, Any], outcome: Literal["passed", "failed", "skipped"], - longrepr: None - | ExceptionInfo[BaseException] + longrepr: ExceptionInfo[BaseException] | tuple[str, int, str] | str - | TerminalRepr, + | TerminalRepr + | None, when: Literal["setup", "call", "teardown"], sections: Iterable[tuple[str, str]] = (), duration: float = 0, @@ -399,11 +399,11 @@ def from_item_and_call(cls, item: Item, call: CallInfo[None]) -> TestReport: if not call.excinfo: outcome: Literal["passed", "failed", "skipped"] = "passed" longrepr: ( - None - | ExceptionInfo[BaseException] + ExceptionInfo[BaseException] | tuple[str, int, str] | str | TerminalRepr + | None ) = None else: if not isinstance(excinfo, ExceptionInfo): @@ -466,11 +466,11 @@ def __init__( self, nodeid: str, outcome: Literal["passed", "failed", "skipped"], - longrepr: None - | ExceptionInfo[BaseException] + longrepr: ExceptionInfo[BaseException] | tuple[str, int, str] | str - | TerminalRepr, + | TerminalRepr + | None, result: list[Item | Collector] | None, sections: Iterable[tuple[str, str]] = (), **extra, diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index 3f03cfaff77..cb723d134b9 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -408,7 +408,7 @@ def collect() -> list[Item | Collector]: call = CallInfo.from_call( collect, "collect", reraise=(KeyboardInterrupt, SystemExit) ) - longrepr: None | tuple[str, int, str] | str | TerminalRepr = None + longrepr: tuple[str, int, str] | str | TerminalRepr | None = None if not call.excinfo: outcome: Literal["passed", "skipped", "failed"] = "passed" else: diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index e3de07a7c9b..852153b9215 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -400,7 +400,7 @@ def __init__(self, config: Config, file: TextIO | None = None) -> None: file = sys.stdout self._tw = _pytest.config.create_terminal_writer(config, file) self._screen_width = self._tw.fullwidth - self.currentfspath: None | Path | str | int = None + self.currentfspath: Path | str | int | None = None self.reportchars = getreportopt(config) self.foldskipped = config.option.fold_skipped self.hasmarkup = self._tw.hasmarkup diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index 654c99271c5..566071d47a1 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -175,7 +175,7 @@ class Exc(Exception): def __repr__(self): return "Exc(from_gen)" - def gen() -> Iterator[int | None | Exc]: + def gen() -> Iterator[int | Exc | None]: yield 0 yield None yield Exc()