Skip to content

Add class doc string to native_enum #5617

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 8 commits into from
Apr 15, 2025
Merged

Conversation

dyollb
Copy link
Contributor

@dyollb dyollb commented Apr 14, 2025

Description

Fixes #5615

Suggested changelog entry:

Add class doc string to `py::native_enum`

@@ -24,9 +24,10 @@ class native_enum : public detail::native_enum_data {

native_enum(const object &parent_scope,
const char *name,
const char *native_type_name = "enum.Enum")
const char *native_type_name,
const char *doc = "")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Drive-by comment: Could you please use the same (longer) name consistently here and in native_enum_data.h?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@dyollb
Copy link
Contributor Author

dyollb commented Apr 14, 2025

Locally this test in test_member_doc fails if I have a default enum_doc="":

assert m.member_doc.mem1.__doc__ == pure_native.mem.__doc__

It seems the class doc string is inherited (together with all public class methods) unless overridden in the value.

@henryiii
Copy link
Collaborator

I think we need to update the docs too?

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.

@henryiii wrote: I think we need to update the docs too?

+1

An easy way to pin-point the documentation that needs to be tweaked is to look here:

https://github.com/pybind/pybind11/pull/5555/files

@@ -29,10 +29,12 @@ class native_enum_data {
native_enum_data(const object &parent_scope,
const char *enum_name,
const char *native_type_name,
const char *enum_doc,
Copy link
Collaborator

Choose a reason for hiding this comment

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

You're using "class doc" in the PR title and the added test: I think it's a much better name than enum_doc here, because then it is crystal clear that it does not apply to the enum members. Could you please use class_doc here (and in native_enum.h), too?

Copy link
Contributor Author

@dyollb dyollb left a comment

Choose a reason for hiding this comment

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

Thanks

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.

Thanks @dyollb for the work!

@rwgk rwgk merged commit 3c58634 into pybind:master Apr 15, 2025
2 checks passed
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Apr 15, 2025
b-pass pushed a commit to b-pass/pybind11 that referenced this pull request May 9, 2025
* add class doc string to native_enum

* adapt doc argument name

* fix test, make class enum doc None by default

* fix other python versions?

* make clang-tidy happy

* rename 'enum_doc' to 'class_doc'

* update documentation

* [skip ci] Polish changed documentation (mostly done by ChatGPT).

---------

Co-authored-by: Bryn Lloyd <[email protected]>
Co-authored-by: Ralf W. Grosse-Kunstleve <[email protected]>
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.

[BUG]: the new native_enum does not support class doc strings
3 participants