Skip to content

source-control: babysit_util type-check helpers should be TypeGuards, deleting ~12 casts in merge/gh #3448

Closed

Description

@kyle-sexton

Context

Found by the repo-wide /code-tidying:batch-simplify sweep (62 groups / 986 files, branch claude/repo-code-tidying-batch-twhddw). Deferred from the sweep as dedicated-PR-shaped work: the consolidation crosses file or contract boundaries a behavior-preserving sweep must not cross.

plugins/source-control/skills/babysit-prs/scripts/babysit_util.py:29 — converting the is_* helpers to TypeGuard returns deletes ~12 casts in babysit_merge/babysit_gh. One-diff change owned by the util module.

Proposed work

  • Convert to typing.TypeGuard and drop the now-redundant casts.

Acceptance criteria

  • mypy/pyright clean with the casts removed; test suite green.

References

  • plugins/source-control/skills/babysit-prs/scripts/babysit_util.py:29

Filed by the /code-tidying:batch-simplify closeout (Phase 8).

Activity

  1. added theissue type on Aug 27, 2026
  2. added
    needs-triage
    on Aug 27, 2026
  3. claude commented on Sep 6, 2026

    @claude
    Contributor

    Generated by Claude Code

  4. claude commented on Sep 6, 2026

    @claude
    Contributor

    This was generated by AI during triage.

    Triage verification (2026-09-06)

    Claim holds, and the payoff is larger than filed. The type-check helpers in the babysit utility module still return plain booleans, so a caller learns nothing about the value's type from calling them and must cast afterwards. The cast count has grown: the merge module now carries 17 cast sites, against the roughly 12 the body estimated. One correction to scope: the body names both the merge and the gh modules as beneficiaries, but the gh module currently has no casts, so the deletions land in the merge module.

    Agent Brief

    Type: Task (refactor)

    Summary: Convert the babysit utility module's type-check predicates to type guards so callers narrow the value directly and the redundant casts disappear.

    Current behavior:
    The utility module exposes predicates that answer whether a decoded JSON value is an object or an array, returning a plain boolean. Because the return type carries no narrowing information, every caller that acts on a true result must add a cast to tell the type checker what the predicate already proved. Those casts are pure ceremony: they restate a fact the predicate established, and each one is a place where a wrong type could be asserted without the checker objecting.

    Desired behavior:
    The predicates return a type guard, so a true result narrows the value at the call site. The casts that existed only to restate the predicate's result are deleted. No runtime behavior changes: the predicates test the same conditions and return the same values.

    Key interfaces:

    • The babysit utility module's JSON type-check predicates, whose return annotations change from a plain boolean to a type guard over the narrowed type.
    • Their callers in the babysit merge module, where the redundant casts are removed.

    Acceptance criteria:

    • The type-check predicates return type guards.
    • Casts made redundant by the narrowing are deleted; no cast remains that only restates a predicate result.
    • The repository's configured Python type checker passes with the casts removed.
    • The babysit test suite is green, and no runtime behavior changes.
    • scripts/affected-tests.sh --run passes for the touched surfaces.

    Out of scope:

    • Any other change to the babysit utility module or to the merge module's logic.
    • Introducing type guards elsewhere in the plugin.
    • The guarded-mutation preamble consolidation tracked separately in the same script family.

    Generated by Claude Code

  5. added
    status: ready
    agent-ready
    and removed
    needs-triage
    on Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readystatus: ready

    Type

    Fields

    No fields configured for Task.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions