From 050df5595c136850e9b7bc16d99bb7936c2fc3c9 Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Thu, 31 Aug 2023 03:28:41 +0900 Subject: [PATCH 1/2] fix: Enum __str__ function name --- include/pybind11/pybind11.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index db91639dc0..e6c9ad0ac1 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -2014,7 +2014,7 @@ struct enum_base { object type_name = type::handle_of(arg).attr("__name__"); return pybind11::str("{}.{}").format(std::move(type_name), enum_name(arg)); }, - name("name"), + name("__str__"), is_method(m_base)); if (options::show_enum_members_docstring()) { From 6a266fd9e100ea6587d5c872deece6c1f5d27aa6 Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Thu, 31 Aug 2023 03:29:09 +0900 Subject: [PATCH 2/2] tests: Test enum.__str__.__doc__ --- tests/test_enum.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_enum.py b/tests/test_enum.py index 4e85d29c31..b97b0fa567 100644 --- a/tests/test_enum.py +++ b/tests/test_enum.py @@ -264,3 +264,8 @@ def test_docstring_signatures(): for attr in enum_type.__dict__.values(): # Issue #2623/PR #2637: Add argument names to enum_ methods assert "arg0" not in (attr.__doc__ or "") + + +def test_str_signature(): + for enum_type in [m.ScopedEnum, m.UnscopedEnum]: + assert enum_type.__str__.__doc__.startswith("__str__")