Skip to content

Fix py::kw_only when used before the first arg of a method #3488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 21, 2021

Conversation

jagerman
Copy link
Member

The implicit space for the self argument isn't added until we hit the first argument, but this wasn't being done for kw_only or pos_only that happen before the first argument, and so a kw_only before the first argument on methods/constructors would break.

This fixes it by properly checking whether we need to add the self arg in those places as well.

(The pos_only issue here was extremely mild -- you didn't get the / in the docstring, but AFAICT it has no other effect since there are no meaningful arguments before it anyway).

Closes #3789 (thanks to @rwgk for the minimal test case in that PR).

The implicit space for the `self` argument isn't added until we hit the
first argument, but this wasn't being done for kw_only or pos_only, and
so a kw_only before the first argument would break.

This fixes it by properly checking whether we need to add the self arg.

(The pos_only issue here was extremely mild -- you didn't get the `/` in
the docstring, but AFAICT it has no other effect since there are no
meaningful arguments before it anyway).
@jagerman jagerman requested a review from rwgk November 20, 2021 13:15
Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

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

Awesome, thanks a lot Jason!

@rwgk
Copy link
Collaborator

rwgk commented Nov 20, 2021

For the record: I ran the clang sanitizers (asan, msan, tsan, ubsan) with this PR included. All fine. (There are only a handful of known long-standing failures.)

I also initiated Google global testing (includes testing many OSS packages). Results in ~7 hours. But I think it's safe to merge this PR asap.

- rename check_have_self_arg -> append_self_arg_if_needed

- move the argument name inline comments before the args instead of
  after
@rwgk
Copy link
Collaborator

rwgk commented Nov 21, 2021

Thanks Jason! — In the meantime the Google-global testing finished without issues. I'll go ahead with merging this PR.

@rwgk rwgk merged commit 673b4be into pybind:master Nov 21, 2021
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Nov 21, 2021
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Dec 2, 2021
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.

3 participants