Skip to content

Fix argument forwarding to partial callbacks - #818

Open
HocVoNgThai wants to merge 2 commits into
pytest-dev:mainfrom
HocVoNgThai:fix/partial-extra-arguments
Open

HocVoNgThai wants to merge 2 commits into
pytest-dev:mainfrom
HocVoNgThai:fix/partial-extra-arguments

Conversation

@HocVoNgThai

Copy link
Copy Markdown

HookCaller.call_extra() loses the remaining arguments of a functools.partial callback. Required parameters raise TypeError, while defaulted parameters silently receive their own default instead of the caller's value.

For example, binding "demo" to on_event(context, value) with partial(on_event, "demo") and calling the hook with value=7 currently raises a missing-argument error. This change returns [("demo", 7)].

Read the partial's bound signature when extracting parameter names.

Closes #817

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Written by Claude Opus 5.5 via Claude Code for the pluggy maintainers; I prompted it, it did the work, I read it.

The diagnosis in #817 is right, but this needs more before it can be merged:

  • No tests. Please add varnames cases in testing/test_helpers.py and a call_extra regression test.
  • No changelog fragment (changelog/817.bugfix.rst).
  • Keyword binding still fails. partial(f, ctx="c") makes every later parameter keyword-only, and the new branch drops keyword-only parameters, so call_extra still raises TypeError. The same happens with g(value, ctx, other) and partial(g, ctx="c"): other is lost.
  • follow_wrapped=False breaks partials of functools.wraps-decorated functions, which varnames() supports for plain functions (test_varnames_decorator).
  • The except (TypeError, ValueError) fallback is untested, and returning ((), ()) silently reproduces the original bug.
  • Why only functools.partial? Any callable whose __call__ has no __code__ hits the same path; an inspect.signature fallback there would fix the root cause.

Generated by Claude Code

@HocVoNgThai

Copy link
Copy Markdown
Author

Updated in 73d5166 to address the review, including the requested tests and changelog. Tests pass on Python 3.10, 3.12 and 3.14, and all pre-commit checks pass. Thanks for the review!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

call_extra() drops arguments for partial callbacks

2 participants