Skip to content

chore: improve Python code quality in range42-context-tui.py and range42-init.py #215

@t0kubetsu

Description

@t0kubetsu

Context

While working on CI hardening (feat/ci-hardening), we attempted to enable ruff check --select ALL across the Python codebase. All three Python files surfaced violations that could not be addressed through incremental patching — the code structure itself makes clean compliance impractical.

  • Broad except Exception clauses throughout (BLE001)
  • Missing type annotations on most functions and methods (ANN001/ANN202/ANN204)
  • Missing or malformed docstrings across all classes and methods (D101/D102/D107)
  • print() calls instead of structured logging (T201)
  • os.path instead of pathlib (PTH109/PTH112/PTH118)
  • Mutable class-level attributes without ClassVar annotation (RUF012)
  • Complexity violations in _populate_commands and _spawn_subprocess (C901/PLR0912/PLR0915)
  • try/except/pass patterns that silently swallow errors (SIM105/S110)
  • Inline try/except on single lines (E701)
  • Private member access across class boundaries — self.app._log_line (SLF001)

Proposal

All three files would benefit from a clean rewrite following current Python best practices:

  • from __future__ import annotations + full type annotations
  • logging module replacing all print() calls
  • pathlib.Path throughout
  • Specific exception types everywhere
  • contextlib.suppress() where appropriate
  • Docstrings on all public classes and methods
  • ClassVar annotations on class-level mutables
  • Helper methods to keep function complexity below threshold

This would also make the CI gate (ruff check --select ALL) unconditionally green, which is the goal of feat/ci-hardening.

Files concerned

  • range42-context-tui.py
  • range42-init.py
  • wizard/preflight.py

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions