← Back to Pull requests

Type Checking Part 2: Validate configuration arguments before invoking actions #14347

Merged
notatallshaw merged 3 files (120 lines) on Oct 14, 2026 22:10 UTC
View on GitHub
notatallshaw notatallshaw commented on Oct 12, 2026 05:31 UTC
Author

<!---
Thank you for your pull request! Before submitting, please make sure you've:

  • Read the CONTRIBUTING.md file carefully

  • Added a news file fragment (see https://pip.pypa.io/en/latest/development/contributing/#news-entries)

  • -->

    What does this PR do?

    The is two of (currently) seven PRs to get nox -s typecheck checking to pass.

    This fixes a bug, with an editor configured, pip config edit unexpected opens the configuration file and silently ignores the extra argument. Other configuration actions reject incorrect argument counts.

    Each configuration action declares the arguments it accepts. Dispatch checks those arguments before calling the action and reports the existing argument-count error if they do not match. A TypeError from within the action is allowed to propagate.

    Design

    I chose to go with inspect / reflection rather than have each action explicitly and statically register their own arguments. But I would be happy to change.

    PR Checklist:


    <!--- Go over all the following points, and put an x in all the boxes that apply. -->
  • I agree to follow the PSF Code of Conduct.

  • I have read and have followed the CONTRIBUTING.md file.

  • I have added a news file fragment (or this PR does not need one).

  • I have read and followed the AI_POLICY.md file, and if any AI tools were used, I have disclosed it below.

  • <!-- If checked and you have used AI tools, add a line below: Assisted-by: <tool name, e.g. Claude> -->

    Diff: 120 lines (+89 / -31) across 3 files Reviewer: None requested Review duration: 3878m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.70) × (1 − Review Confidence (0.67)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.70 · 120 lines diff across 3 files
    0.70
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.59 · 2 substantive comment(s)
    0.59
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 10%
    67%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.287
    No Reviewer Assigned no_reviewer_assigned
    0.120
    Sensitive Paths sensitive_paths
    0.070
    Real PR Conversation Timeline
    3 items
    ichard26 ichard26 commented on code on Oct 14, 2026 21:32 UTC
    Code Review
    src/pip/_internal/commands/configuration.py:1
    @@ -22,6 +22,30 @@
     logger = logging.getLogger(__name__)
     
     
    +def _config_handler(
    +    name: str, handler: Callable[..., None]
    +) -> Callable[[Values, list[str]], None]:
    +    """Adapt a configuration action's positional parameters to CLI arguments."""
    +    signature = inspect.signature(handler)
    +    # These are bound methods: only the options parameter precedes CLI arguments.
    +    arguments = list(signature.parameters)[1:]
    +    example = " ".join([name, *(f"[{argument}]" for argument in arguments)])

    Let's only build an example string if the arguments don't match, so it's more obvious it's only for error formatting.

    notatallshaw notatallshaw commented on code on Oct 14, 2026 22:09 UTC
    Code Review
    src/pip/_internal/commands/configuration.py:1
    @@ -22,6 +22,30 @@
     logger = logging.getLogger(__name__)
     
     
    +def _config_handler(
    +    name: str, handler: Callable[..., None]
    +) -> Callable[[Values, list[str]], None]:
    +    """Adapt a configuration action's positional parameters to CLI arguments."""
    +    signature = inspect.signature(handler)
    +    # These are bound methods: only the options parameter precedes CLI arguments.
    +    arguments = list(signature.parameters)[1:]
    +    example = " ".join([name, *(f"[{argument}]" for argument in arguments)])

    Makes sense.

    Reviewers
    None requested
    Assignees
    notatallshaw notatallshaw
    Labels
    risk: low confidence: 67.2% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 69.8% (HIGH) · Higher = larger blast radius
    69.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 67.2% · Lower = rushed or shallow review
    67.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.9% · Safe to merge
    22.9%
    Repository