Skip to content

fix: correct args_convert flags for kw-only args after py::args - #6160

Merged
rwgk merged 1 commit into
pybind:masterfrom
henryiii:fix/dispatcher-kwonly-convert
Nov 21, 2026
Merged

rwgk merged 1 commit into
pybind:masterfrom
henryiii:fix/dispatcher-kwonly-convert

Conversation

@henryiii

@henryiii henryiii commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

Description

Two related problems in the function dispatcher, items 1 and 2 of #6159.

When named arguments follow py::args, the dispatcher pushes a stub for the *args tuple into call.args in step 2, but appended its convert flag at the end in step 4a. Each keyword-only argument thus got the convert flag of the next argument, so py::arg("x").noconvert() applied to the wrong argument. The flag is now pushed together with the stub, and step 4a appends a flag only when it appends the tuple itself.

The second-pass scan stopped at pos_args. An overload whose only convertible arguments are keyword-only was thus never retried with conversion permitted. The scan now examines all of the flags.

Both problems have new tests in tests/test_kwargs_and_defaults.

Suggested changelog entry:

  • Fixed the noconvert flags and the overload second pass for keyword-only arguments that follow py::args.

The `*args` stub was pushed into `call.args` in step 2, but its convert
flag was appended after all of the keyword-only flags in step 4a. Each
keyword-only argument thus received the flag of its successor, so
`py::arg("x").noconvert()` applied to the wrong argument. Push the flag
together with the stub, and append it in step 4a only when the tuple
itself is appended.

The second-pass scan also stopped at `pos_args`, so an overload whose
only convertible arguments are keyword-only never got a converting pass.
Scan all of the flags instead.

Fixes items 1 and 2 of pybind#6159.
@henryiii
henryiii force-pushed the fix/dispatcher-kwonly-convert branch from 9ad21a0 to 00164bb Compare November 12, 2026 15:06
@rwgk
rwgk merged commit 087b4b0 into pybind:master Nov 21, 2026
102 checks passed
@rwgk
rwgk deleted the fix/dispatcher-kwonly-convert branch November 21, 2026 18:36
@github-actions github-actions Bot added the needs changelog Possibly needs a changelog entry label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs changelog Possibly needs a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants