Skip to content

[Code Quality] Fix stdlib import ordering in api_client.py and enforce with ruff I rules #545

@github-actions

Description

@github-actions

Description

api_client.py (extracted from main.py as part of the modularization effort in #473/#516) has a stdlib-after-third-party import ordering violation:

# api_client.py lines 31–32 (current — incorrect order)
import httpx        # third-party
import contextlib   # stdlib — should come BEFORE third-party imports

PEP 8 and isort require: stdlib → third-party → local. The current ruff config (pyproject.toml) selects E, W, F, RET, SIM, UP but not I (isort), so this violation is not caught by CI today.

Adding "I" to the ruff select list and fixing the violation ensures consistent import ordering is automatically enforced across all current and future modules (config.py, validation.py, etc.).

Suggested Changes

  1. Fix api_client.py — move import contextlib before import httpx:
from __future__ import annotations

import contextlib   # ← move here (stdlib section)
import logging
import random
import threading
import time
from collections.abc import Callable
from typing import Any

import httpx        # ← third-party stays here
  1. Update pyproject.toml — add "I" to the ruff select list:
[tool.ruff.lint]
select = [
    "E",
    "W",
    "F",
    "I",     # ← add isort
    "RET",
    "SIM",
    "UP",
]
  1. Verify no other violations introduced by the new rule:
uv tool run ruff check . --select I
uv tool run ruff check . --select I --fix   # auto-fixable

Files Affected

  • api_client.py — reorder import contextlib into the stdlib block
  • pyproject.toml — add "I" to [tool.ruff.lint] select

Success Criteria

  • api_client.py: import contextlib precedes import httpx
  • "I" appears in [tool.ruff.lint] select in pyproject.toml
  • uv tool run ruff check . --select I exits clean
  • ✅ All existing tests pass: uv run pytest tests/ -v

Source

Import ordering violation observed during code review of the modularization output (Daily Backlog Burner discussion #493 — staged extraction of api_client.py, cache.py, validation.py). Complements the B (flake8-bugbear) rule addition in #543.

Priority

Low — 2-line fix + 1-line config change. The I rule is auto-fixable and prevents future import ordering drift as more modules are extracted from main.py.

🔍 Task mining by Discussion Task Miner - Code Quality Improvement Agent

To install this agentic workflow, run

gh aw add github/gh-aw/.github/workflows/discussion-task-miner.md@94662b1dee8ce96c876ba9f33b3ab8be32de82a4
  • expires on Mar 5, 2026, 1:41 PM UTC

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions