← Back to Pull requests

LocalPythonExecutor: bind keyword-only and positional-only parameters #3170

Closed
unknown closed this pull request without merging on Nov 15, 2026 11:46 UTC
View on GitHub
unknown unknown commented on Nov 14, 2026 02:23 UTC
Author

LocalPythonExecutor never looks at kwonlyargs / posonlyargs when it builds a function's frame, so an ordinary signature silently turns into an undefined variable.

def f(*, a=3):
    return a

f()  # InterpreterError: The variable `a` is not defined.

Fixes #3161

Same line of code, two more things that fall over (from #3165):

def g(a, /, b=2):
    return a + b

g(1)  # InterpreterError: The variable `a` is not defined.

and the except ... as name target stays bound in executor.state after the handler is done:

try:
    1 / 0
except ZeroDivisionError as caught:
    handled = str(caught)

"caught" in executor.state  # True

What changed

create_function:

  • positional names are now (posonlyargs, args). They sit first in the signature, so / parameters bind the same way as the rest.

  • kw-only defaults are zipped against kw_defaults and merged into the same defaults dict. kw_defaults keeps a None placeholder for parameters that have no default (def f(, a, b=1)), those are skipped, same as CPython.

  • defaults are evaluated once, in create_function itself, instead of on every call. They are still evaluated with the defining scope as state, so a default that closes over a name keeps working, but def f(, value=allocate()) now allocates once instead of once per call (and an explicit f(value=99) doesn't evaluate it at all, which it used to). The positional side had the same problem, so both are captured at definition time.

  • a positional-only name passed by keyword doesn't bind the parameter, it lands in kwargs: def f(a, /, kw) called as f(1, a=2) is (1, {'a': 2}), not (2, {'a': 2}).
  • evaluate_try:

  • the handler body runs inside try/finally, and the finally pops the handler name from state. That's what makes del caught happen on a normal exit, a return out of the handler, or an exception thrown from the handler. The exception object is what keeps its traceback (and every frame in it) alive, so dropping the name also stops the executor from holding onto a whole traceback for the rest of the run.
  • except X without as is untouched, and so is the re-raise path when no handler matches.

    Tests

    Added to tests/test_local_python_executor.py:

  • test_keyword_only_default_arg_in_function

  • test_positional_only_arg_in_function

  • test_positional_only_name_passed_by_keyword_goes_to_kwargs

  • test_default_values_are_evaluated_once_at_definition

  • test_exception_target_is_unbound_after_the_handler (also checks the name shadows an outer variable only inside the handler)

  • test_exception_target_is_unbound_when_the_handler_raises
  • All six fail on 96f33fa without the source change, all six pass with it.

    tests/test_local_python_executor.py + tests/test_tool_validation.py
      before: 9 failed, 410 passed, 2 skipped
      after:  3 failed, 416 passed, 2 skipped
    

    The 3 remaining failures are environment ones and fail identically on 96f33fa (sklearn not installed; two pandas chained-comparison cases that depend on the pandas version). I diffed the failing test list of the wider suite before and after (64 failed / 864 passed vs 68 failed / 858 passed), the only difference is the tests added here flipping to green.

    Diff: 410 lines (+307 / -103) across 5 files Reviewer: its-amann Review duration: 2002m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.45) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 410 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    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.360
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3170"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    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: 44.9% (MEDIUM) · Higher = larger blast radius
    44.9%
    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: 56.8% · Lower = rushed or shallow review
    56.8%
    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: 19.4% · Safe to merge
    19.4%