Skip to content

Preserve positional-only signatures in funcutils wrappers - #511

Open
ZelinZhu-Richard wants to merge 1 commit into
mahmoud:masterfrom
ZelinZhu-Richard:fix/funcutils-positional-only-signatures
Open

ZelinZhu-Richard wants to merge 1 commit into
mahmoud:masterfrom
ZelinZhu-Richard:fix/funcutils-positional-only-signatures

Conversation

@ZelinZhu-Richard

@ZelinZhu-Richard ZelinZhu-Richard commented Sep 19, 2026

Copy link
Copy Markdown

The change

Fixes #510. A wrapper around def f(a, /, **kw) currently raises TypeError for the valid call f(1, a=2), because its generated signature loses /.

from boltons.funcutils import wraps

def original(a, /, **kw):
    return a, kw

@wraps(original)
def wrapped(*args, **kwargs):
    return original(*args, **kwargs)

wrapped(1, a=2)  # Expected: (1, {'a': 2}); previously raised TypeError

Pass the existing positional-only metadata through the signature formatter and keep it synchronized when arguments are removed. The formatter gains an optional trailing posonlyargs argument; invocation forwarding is unchanged. Tests cover keyword-name collisions, rejected keyword binding, defaults and annotations, mixed signatures, and injected argument removal.

Validation:

  • All six new regressions fail on the original code and pass with the fix.
  • Full tox suite: 678 tests/doctests passed.
  • Focused funcutils suite: 48 passed; git diff --check passed.
  • test_wraps_posonly_keyword_collision and test_wraps_posonly_rejects_keyword_binding cover keyword collisions and rejection of keyword binding to positional-only parameters.
  • test_formatargspec_posonly_defaults_and_annotations and test_wraps_posonly_mixed_signature cover defaults, annotations, variadic arguments, and generated signatures.
  • test_FunctionBuilder_remove_posonly_args and test_wraps_injected_posonly_arg cover argument removal and injection.

New positional-only test definitions use guarded exec, following the existing tests. Compatibility grammar checks passed; the full supported-interpreter matrix has not been run.

AI assistance

  • Harness/tooling: Codex desktop, with separate implementation and review subagents. Codex found the bug, wrote the patch and tests, ran validation, and prepared this submission.
  • Model(s): GPT-6; a more specific runtime model identifier was not exposed to the agents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

funcutils.wraps drops positional-only parameters from generated signatures

1 participant