Skip to content

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

Open
henryiii wants to merge 1 commit into
pybind:masterfrom
henryiii:fix/dispatcher-kwonly-convert
Open

fix: correct args_convert flags for kw-only args after py::args#6160
henryiii wants to merge 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.
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.

1 participant