From 83e77ca12e08284b6c75b25bd15867b516f76919 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Fri, 11 Sep 2026 17:41:30 +0200 Subject: [PATCH] python-tools.sh: Annotate generated conftest.py create-conftest-py generates the conftest.py that pytest test directories pick up at build time, and make clean removes it. The generated file lacks type annotations, though: pytest_configure() and the nested patched() take untyped parameters, and the replacement of .pytest_sessionstart() on the class is rejected by strict mypy. Emit a type-annotated version instead: add a future annotations import, type both functions, move the types that are only used in annotations behind a TYPE_CHECKING guard, and silence the method replacement with a targeted type ignore. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1 Signed-off-by: Jan Lindemann --- scripts/python-tools.sh | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/scripts/python-tools.sh b/scripts/python-tools.sh index 0b189d7b..a981be88 100644 --- a/scripts/python-tools.sh +++ b/scripts/python-tools.sh @@ -35,17 +35,25 @@ module_path() cmd_create_conftest_py() { cat <<-'EOT' + from __future__ import annotations + import os - import sys import shutil + import sys - def pytest_configure(config): - import _pytest.terminal - import _pytest.timing as timing + from typing import TYPE_CHECKING - # orig = _pytest.terminal.TerminalReporter.pytest_sessionstart + from _pytest.terminal import TerminalReporter + from _pytest.timing import Instant - def patched(self, session): + if TYPE_CHECKING: + from _pytest.config import Config + from _pytest.main import Session + + def pytest_configure(config: Config) -> None: + """Print a banner centered in the terminal when the session starts.""" + + def patched(self: TerminalReporter, session: Session) -> None: width = shutil.get_terminal_size().columns d = os.path.basename(os.getcwd()) text = f"Running pytest for {d}" @@ -59,9 +67,9 @@ cmd_create_conftest_py() banner = text print(banner, file = sys.stderr) self._session = session - self._session_start = timing.Instant() + self._session_start = Instant() - _pytest.terminal.TerminalReporter.pytest_sessionstart = patched + TerminalReporter.pytest_sessionstart = patched # type: ignore[method-assign] EOT }