style: modernise typing and clean up lint findings

Repository-wide mechanical cleanup so `ruff check src tests` has a chance
of passing; no behavioural changes.

- Add `from __future__ import annotations` where PEP 604 unions are used.
  This has to come first: pyproject declares requires-python >= 3.9, where
  `X | None` is not evaluable at runtime unless annotations are stringified.
- Replace typing.List/Dict/Tuple/Set with the builtin generics and
  Optional[X] with X | None, then drop the imports that became unused.
  The four actions/*/__init__.py files needed this by hand because ruff
  leaves unused imports in __init__.py alone (possible re-exports).
- Strip shebangs from 72 importable modules. None of them are executable
  or invoked directly; the entry points are console_scripts and runpy.
- Flatten nested `with` blocks, collapse needless-bool returns, and apply
  the remaining mechanical ruff fixes (PIE810, FLY002, PERF102, FURB192,
  RUF059, I001).
- Pass check=False explicitly to the four subprocess.run() calls that
  inspect returncode themselves. That is the existing default.

Two rewrites are visible to mocks, so their tests move with them:
subprocess.run(stdout=PIPE, stderr=PIPE) became capture_output=True, and
open(path, "r", ...) lost the redundant mode.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-Birkenbach
2026-07-27 16:47:13 +02:00
parent 14b95d5639
commit b4e0594901
187 changed files with 591 additions and 856 deletions

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
"""
CLI integration tests for `pkgmgr mirror`.
@@ -21,7 +19,6 @@ import runpy
import sys
import unittest
from contextlib import ExitStack, redirect_stderr, redirect_stdout
from typing import Dict, List, Optional
from unittest.mock import MagicMock, PropertyMock, patch
@@ -29,7 +26,7 @@ class TestIntegrationMirrorCommands(unittest.TestCase):
"""Integration tests for `pkgmgr mirror` commands."""
def _run_pkgmgr(
self, args: List[str], extra_env: Optional[Dict[str, str]] = None
self, args: list[str], extra_env: dict[str, str] | None = None
) -> str:
"""Execute pkgmgr with the given arguments and return captured output."""
original_argv = list(sys.argv)
@@ -151,8 +148,7 @@ class TestIntegrationMirrorCommands(unittest.TestCase):
code = exc.code if isinstance(exc.code, int) else None
if code not in (0, None):
raise AssertionError(
"%r failed with exit code %r.\n\nOutput:\n%s"
% (cmd_repr, exc.code, buffer.getvalue())
f"{cmd_repr!r} failed with exit code {exc.code!r}.\n\nOutput:\n{buffer.getvalue()}"
)
return buffer.getvalue()